Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, [], [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! can we add both examples?

Copy link
Copy Markdown
Contributor Author

@kirya-dev kirya-dev Aug 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean addHelp & setHelps ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member

@franmomu franmomu Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I meant like:

->add('field_with_help_in_form_options', null, ['help' => '<p>...</p>'])
->add('field_with_help_in_field_description_options', null, [], ['help' => '<p>...</p>'])

The idea with the original example I wrote was showing that if the help message contains HTML, the user should add help_html, so maybe I should've added two separated examples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe.. But in new example we showing two moments how stop throwing deprecating notices

'help' => 'Help text <small>Please!</small>',
])
->add('field2')
->addHelp('field2', 'This field is required.')
Comment thread
jordisala1991 marked this conversation as resolved.
->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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version where this method was deprecated is already released, so "3.74" should be used instead of "3.x".

*
* @return string
*/
public function getHelp()
{
@trigger_error(sprintf(
Comment thread
kirya-dev marked this conversation as resolved.
'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
4 changes: 2 additions & 2 deletions src/Form/FormMapper.php
Original file line number Diff line number Diff line change
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) {
Comment thread
greg0ire marked this conversation as resolved.
@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
25 changes: 13 additions & 12 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 @@ -153,13 +155,13 @@ file that was distributed with this source code.
{% endif %}

<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{% if translation_domain is same as(false) %}
{%- if translation_domain is same as(false) -%}
{{- label -}}
{% elseif not sonata_admin.admin %}
{%- elseif not sonata_admin.admin -%}
{{- label|trans(label_translation_parameters, translation_domain) -}}
{% else %}
{{ label|trans(label_translation_parameters, sonata_admin.field_description.translationDomain ?: admin.translationDomain) }}
{% endif %}
{%- else -%}
{{- label|trans(label_translation_parameters, sonata_admin.field_description.translationDomain ?: admin.translationDomain) -}}
{%- endif -%}
</label>
{% endif %}
{% endapply %}
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