Skip to content

Commit

Permalink
Fix help deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
kirya-dev authored and jordisala1991 committed Aug 30, 2020
1 parent 951df1a commit 63de836
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
14 changes: 13 additions & 1 deletion UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ 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>',
])
->add('field2')
->addHelp('field2', 'This field is required.')
->add('field3')
->setHelps([
'field3' => 'Great day to great work!',
]);
```

Expand All @@ -51,6 +57,12 @@ $formMapper
->add('field', null, [
'help' => 'Help text <small>Please!</small>',
'help_html' => true,
])
->add('field2', null, [
'help' => 'This field is required.'
])
->add('field3', null, [
'help' => 'Great day to great work!'
]);
```

Expand Down
19 changes: 14 additions & 5 deletions src/Admin/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,22 @@ 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);
if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
@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
15 changes: 8 additions & 7 deletions src/Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ 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 %}
{# NEXT_MAJOR: Remove class sonata-ba-field-widget-help #}
{% set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block sonata-ba-field-widget-help sonata-ba-field-help')}) %}
{{ parent() }}
{% endif %}
{%- endblock form_help %}

{% block form_widget -%}
{{ parent() }}
Expand Down Expand Up @@ -401,8 +403,7 @@ file that was distributed with this source code.
{% endif %}

{# NEXT_MAJOR: Remove this block #}
{% if sonata_admin is defined and sonata_admin_enabled and sonata_admin.field_description.help|default(false) %}
{% deprecated 'The "help" option is deprecated in field description since sonata-project/admin-bundle 3.74, to be removed in 4.0. Use Symfony Form "help" option instead.' %}
{% if sonata_admin is defined and sonata_admin_enabled and sonata_admin.field_description.getHelp('sonata_deprecation_mute')|default(false) %}
<span class="help-block sonata-ba-field-help">{{ sonata_admin.field_description.help|trans(help_translation_parameters, sonata_admin.field_description.translationDomain ?: admin.translationDomain)|raw }}</span>
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Controller/CRUDControllerTest.php
Original file line number Diff line number Diff line change
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 63de836

Please sign in to comment.