Skip to content

Commit

Permalink
Fix help deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
kirya-dev committed Aug 27, 2020
1 parent 0740ee1 commit a6961b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-3.x.md
Expand Up @@ -40,7 +40,7 @@ You MUST use Symfony's [`help`](https://symfony.com/doc/4.4/reference/forms/type
Before:
```php
$formMapper
->add('field', null, [
->add('field', null, [], [
'help' => 'Help text <small>Please!</small>',
]);
```
Expand Down
13 changes: 7 additions & 6 deletions src/Admin/BaseFieldDescription.php
Expand Up @@ -475,14 +475,15 @@ public function setHelp($help)
$this->help = $help;
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0. Use Symfony Form "help" option instead.
*
* @return string
*/
public function getHelp()
{
@trigger_error(sprintf(
'The "%s()" method is deprecated since sonata-project/admin-bundle 3.74 and will be removed in version 4.0.'
.' Use Symfony Form "help" option instead.',
__METHOD__
), E_USER_DEPRECATED);

return $this->help;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Form/FormMapper.php
Expand Up @@ -137,10 +137,10 @@ public function add($name, $type = null, array $options = [], array $fieldDescri
}

// NEXT_MAJOR: Remove this block.
if (isset($options['help'])) {
if (isset($options['help']) && !isset($options['help_html'])) {
$containsHtml = $options['help'] !== strip_tags($options['help']);

if (!isset($options['help_html']) && $containsHtml) {
if ($containsHtml) {
@trigger_error(
'Using HTML syntax within the "help" option and not setting the "help_html" option to "true" is deprecated'
.' since sonata-project/admin-bundle 3.74 and it will not work in version 4.0.',
Expand Down
11 changes: 6 additions & 5 deletions src/Resources/views/Form/form_admin_fields.html.twig
Expand Up @@ -33,11 +33,12 @@ file that was distributed with this source code.
{% endapply %}
{% endblock %}

{% block form_help %}
{% apply spaceless %}
<span class="help-block sonata-ba-field-widget-help sonata-ba-field-help">{{ parent() }}</span>
{% endapply %}
{% endblock %}
{% block form_help -%}
{% if help is not empty %}
{% set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block sonata-ba-field-help')}) %}
{{ parent() }}
{% endif %}
{%- endblock form_help %}

{% block form_widget -%}
{{ parent() }}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Controller/CRUDControllerTest.php
Expand Up @@ -52,7 +52,7 @@ public function testCreate(): void
);
$this->assertCount(
1,
$crawler->filter('.sonata-ba-field-help:contains("Help me!")')
$crawler->filter('p.help-block.sonata-ba-field-help:contains("Help me!")')
);
}

Expand Down

0 comments on commit a6961b8

Please sign in to comment.