Skip to content

Commit

Permalink
Fixed the way we handle the form field type
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Mar 7, 2015
1 parent 769b01f commit 57e3642
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
18 changes: 11 additions & 7 deletions Configuration/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,18 @@ protected function getFieldsForFormBasedActions($action, array $entityConfigurat
$entityFields = $this->filterFieldsByNameAndType($this->defaultEntityFields, $excludedFieldNames, $excludedFieldTypes);
}

// to avoid errors when rendering the form, transform Doctrine types to Form component types
// if the user has defined the 'type' for the field, use it. Otherwise,
// guess the best form type using the Doctrine type associated with the field
foreach ($entityFields as $fieldName => $fieldConfiguration) {
$fieldType = $fieldConfiguration['type'];

// don't change this array_key_exists() by isset() because the resulting type can be null
$entityFields[$fieldName]['type'] = array_key_exists($fieldType, $this->doctrineTypeToFormTypeMap)
? $this->doctrineTypeToFormTypeMap[$fieldType]
: $fieldType;
if (!isset($entityConfiguration[$action]['fields'][$fieldName]['type'])) {
$fieldType = $fieldConfiguration['type'];

// don't change this array_key_exists() by isset() because the Doctrine
// type map can return 'null' values that shouldn't be ignored
$entityFields[$fieldName]['type'] = array_key_exists($fieldType, $this->doctrineTypeToFormTypeMap)
? $this->doctrineTypeToFormTypeMap[$fieldType]
: 'text';
}
}

return $entityFields;
Expand Down
26 changes: 13 additions & 13 deletions Resources/doc/6-customizing-new-edit-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ easy_admin:

These are the options that you can define for form fields:

* `property`: it's the name of the associated Doctrine entity property. It
can be a real property or a "virtual property" based on an entity method.
This is the only mandatory option.
* `type`: it's the doctrine type of the field that will be displayed.
It will be converted internally into the [corresponding form type](../../Configuration/Configurator.php#L34)
(from available [Symfony Form Types](http://symfony.com/doc/current/reference/forms/types.html)).
If you don't specify a type, EasyAdmin will guess the best type for it.
* `label`: it's the title that will be displayed for the form field. The
default title is the "humanized" version of the property name.
* `help`: it's the help message that will be displayed below the form field.
* `class`: it's the CSS class that will be applied to the form field widget.
For example, to display a big input field, use the Bootstrap 3 class called
`input-lg`.
* `property` (mandatory): the name of the related Doctrine entity property.
It can be a real property or a "virtual property" based on an entity
method. This is the only mandatory option.
* `type` (optional): the [Symfony Form Type](http://symfony.com/doc/current/reference/forms/types.html)
used to render the field. If you don't specify a type, EasyAdmin will
guess the best type for it.
* `label` (optional): the title that will be displayed for the form field.
The default title is the "humanized" version of the property name.
* `help` (optional): the help message that will be displayed below the
form field.
* `class` (optional): the CSS class that will be applied to the form field
widget. For example, to display a big input field, use the Bootstrap 3
class called `input-lg`.

Add Custom Doctrine Types to Forms
----------------------------------
Expand Down

0 comments on commit 57e3642

Please sign in to comment.