Skip to content

Commit

Permalink
bug #2805 Allow to define the form type help message using the type_o…
Browse files Browse the repository at this point in the history
…ptions config (javiereguiluz)

This PR was squashed before being merged into the 1.x branch (closes #2805).

Discussion
----------

Allow to define the form type help message using the type_options config

This fixes #2795.

Commits
-------

ef9b4fa Allow to define the form type help message using the type_options config
  • Loading branch information
javiereguiluz committed Jun 29, 2019
2 parents 73dcb7f + ef9b4fa commit ef3fd19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/book/edit-new-configuration.rst
Expand Up @@ -360,7 +360,8 @@ These are the options that you can define for each field:
form field. The default label is the "humanized" version of the property name
(e.g. ``published`` is displayed as ``Published`` and ``dateOfBirth`` as
``Date of birth``).
* ``help`` (optional): the help message displayed below the form field.
* ``help`` (optional): the help message displayed below the form field. You can
also define this value via the ``type_options: { help: '...' }`` option.
* ``css_class`` (optional): the CSS class applied to the parent HTML element
that contains the entire form field. For example, when using the default
Bootstrap form theme, this value is applied to the ``<div>`` element which
Expand Down
11 changes: 11 additions & 0 deletions src/Configuration/PropertyConfigPass.php
Expand Up @@ -197,6 +197,17 @@ private function processFieldConfig(array $backendConfig)
$normalizedConfig['type_options'] = $this->getFormTypeOptionsOfProperty(
$normalizedConfig, $fieldMetadata, $originalFieldConfig
);

// EasyAdmin defined a 'help' option before Symfony did the same for form types
// Consider both of them equivalent and copy the 'type_options.help' into 'help'
// to ease further processing of config
if (isset($fieldConfig['help']) && isset($normalizedConfig['type_options']['help'])) {
throw new \RuntimeException(sprintf('The "%s" property in the "%s" view of the "%s" entity defines a help message using both the "help: ..." option from EasyAdmin and the "type_options: { help: ... }" option from Symfony Forms. These two options are equivalent, but you can only define one of them at the same time. Remove one of these two help messages.', $normalizedConfig['property'], $view, $entityName));
}

if (isset($normalizedConfig['type_options']['help']) && !isset($fieldConfig['help'])) {
$normalizedConfig['help'] = $normalizedConfig['type_options']['help'];
}
}

// special case for the 'list' view: 'boolean' properties are displayed
Expand Down

0 comments on commit ef3fd19

Please sign in to comment.