diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 2982e6b66f71a..e8e5f8de46b4f 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * add `help_html` form option to display the `help` text as HTML + 4.2.0 ----- diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig index d281aa0fc7ffc..eaa61a7cfedfc 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig @@ -180,9 +180,17 @@ {%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block')|trim}) -%} {%- if translation_domain is same as(false) -%} - {{- help -}} + {%- if help_html is same as(false) -%} + {{- help -}} + {%- else -%} + {{- help|raw -}} + {%- endif -%} {%- else -%} - {{- help|trans({}, translation_domain) -}} + {%- if help_html is same as(false) -%} + {{- help|trans({}, translation_domain) -}} + {%- else -%} + {{- help|trans({}, translation_domain)|raw -}} + {%- endif -%} {%- endif -%} {%- endif -%} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index acca01bc432a2..1b79dbcac349b 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -305,9 +305,17 @@ {%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-muted')|trim}) -%} {%- if translation_domain is same as(false) -%} - {{- help -}} + {%- if help_html is same as(false) -%} + {{- help -}} + {%- else -%} + {{- help|raw -}} + {%- endif -%} {%- else -%} - {{- help|trans({}, translation_domain) -}} + {%- if help_html is same as(false) -%} + {{- help|trans({}, translation_domain) -}} + {%- else -%} + {{- help|trans({}, translation_domain)|raw -}} + {%- endif -%} {%- endif -%} {%- endif -%} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 6d96cbd221943..4013e0021a54b 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -294,9 +294,17 @@ {%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-text')|trim}) -%}

{%- if translation_domain is same as(false) -%} - {{- help -}} + {%- if help_html is same as(false) -%} + {{- help -}} + {%- else -%} + {{- help|raw -}} + {%- endif -%} {%- else -%} - {{- help|trans({}, translation_domain) -}} + {%- if help_html is same as(false) -%} + {{- help|trans({}, translation_domain) -}} + {%- else -%} + {{- help|trans({}, translation_domain)|raw -}} + {%- endif -%} {%- endif -%}

{%- endif -%} diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index fd1c319a63102..1088b05544796 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -140,6 +140,89 @@ public function testHelpAttr() ); } + public function testHelpHtmlDefaultIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => false, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsTrue() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => true, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + [.="[trans]Help text test![/trans]"] +', 0 + ); + + $this->assertMatchesXpath($html, + '/span + [@id="name_help"] + [@class="help-block"] + /b + [.="text"] +' + ); + } + public function testErrors() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php index bec41597054c4..d2263ea870217 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php @@ -197,6 +197,89 @@ public function testHelpAttr() ); } + public function testHelpHtmlDefaultIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => false, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsTrue() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => true, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + [.="[trans]Help text test![/trans]"] +', 0 + ); + + $this->assertMatchesXpath($html, + '/small + [@id="name_help"] + [@class="form-text text-muted"] + /b + [.="text"] +' + ); + } + public function testErrors() { $form = $this->factory->createNamed('name', TextType::class); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 330b8e70fa7fc..49778e7f85c7e 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -210,6 +210,89 @@ public function testHelpAttr() ); } + public function testHelpHtmlDefaultIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => false, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsTrue() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => true, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +', 0 + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +' + ); + } + protected function renderForm(FormView $view, array $vars = []) { return (string) $this->renderer->renderBlock($view, 'form', $vars); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php index 0b712562a98c7..a1cefcb577d5b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php @@ -96,6 +96,89 @@ public function testHelpAttr() ); } + public function testHelpHtmlDefaultIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => false, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsTrue() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => true, + ]); + + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +', 0 + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +' + ); + } + protected function renderForm(FormView $view, array $vars = []) { return (string) $this->renderer->renderBlock($view, 'form', $vars); diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 75dd4be9f3a46..f1509696a8910 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -24,7 +24,7 @@ "symfony/asset": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/finder": "~3.4|~4.0", - "symfony/form": "^4.2", + "symfony/form": "^4.3", "symfony/http-foundation": "~3.4|~4.0", "symfony/http-kernel": "~3.4|~4.0", "symfony/polyfill-intl-icu": "~1.0", @@ -43,7 +43,7 @@ }, "conflict": { "symfony/console": "<3.4", - "symfony/form": "<4.2", + "symfony/form": "<4.3", "symfony/translation": "<4.2" }, "suggest": { diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 2dd441182d15d..bf61e71953817 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -6,6 +6,8 @@ CHANGELOG * Not passing the project directory to the constructor of the `AssetsInstallCommand` is deprecated. This argument will be mandatory in 5.0. + * Added `ControllerTrait::isFormValid()` + * Added an `help_html` form option to display the `help` text as HTML 4.2.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_help.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_help.html.php index 1490e7ab5f769..fc4b24726cf27 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_help.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_help.html.php @@ -1,4 +1,6 @@ -

block($form, 'attributes', ['attr' => $help_attr]); ?>>escape(false !== $translation_domain ? $view['translator']->trans($help, [], $translation_domain) : $help); ?>

+ trans($help, [], $translation_domain) : $help; ?> + escape($help) : $help ?> +

block($form, 'attributes', ['attr' => $help_attr]); ?>>

diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php index b00b6a10e5337..8d0449cd03b6b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php @@ -113,6 +113,86 @@ public function testHelpAttr() ); } + public function testHelpHtmlDefaultIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + ]); + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsFalse() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => false, + ]); + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +' + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +', 0 + ); + } + + public function testHelpHtmlIsTrue() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [ + 'help' => 'Help text test!', + 'help_html' => true, + ]); + $view = $form->createView(); + $html = $this->renderHelp($view); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + [.="[trans]Help text test![/trans]"] +', 0 + ); + + $this->assertMatchesXpath($html, + '/p + [@id="name_help"] + [@class="help-text"] + /b + [.="text"] +' + ); + } + protected function renderForm(FormView $view, array $vars = []) { return (string) $this->engine->get('form')->form($view, $vars); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index f4ae36a2bc481..713a895e0e66c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -40,7 +40,7 @@ "symfony/dom-crawler": "~3.4|~4.0", "symfony/polyfill-intl-icu": "~1.0", "symfony/security": "~3.4|~4.0", - "symfony/form": "^4.2", + "symfony/form": "^4.3", "symfony/expression-language": "~3.4|~4.0", "symfony/messenger": "^4.2", "symfony/mime": "^4.3", @@ -69,7 +69,7 @@ "symfony/asset": "<3.4", "symfony/console": "<3.4", "symfony/dotenv": "<4.2", - "symfony/form": "<4.2", + "symfony/form": "<4.3", "symfony/messenger": "<4.2", "symfony/property-info": "<3.4", "symfony/serializer": "<4.2", diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 17c3839090866..17c72518239e3 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added `block_prefix` option to `BaseType`. + * added `help_html` option to display the `help` text as HTML. 4.2.0 ----- diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 31757e2887184..3934416ff6dbf 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -91,6 +91,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) 'label_attr' => $options['label_attr'], 'help' => $options['help'], 'help_attr' => $options['help_attr'], + 'help_html' => $options['help_html'], 'compound' => $formConfig->getCompound(), 'method' => $formConfig->getMethod(), 'action' => $formConfig->getAction(), @@ -183,12 +184,14 @@ public function configureOptions(OptionsResolver $resolver) 'allow_file_upload' => false, 'help' => null, 'help_attr' => [], + 'help_html' => false, ]); $resolver->setAllowedTypes('label_attr', 'array'); $resolver->setAllowedTypes('upload_max_size_message', ['callable']); $resolver->setAllowedTypes('help', ['string', 'null']); $resolver->setAllowedTypes('help_attr', 'array'); + $resolver->setAllowedTypes('help_html', 'bool'); } /** diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json index e274979eb8815..c0f335f27ea20 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json @@ -38,6 +38,7 @@ "disabled", "help", "help_attr", + "help_html", "inherit_data", "label", "label_attr", diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt index 7de8dce90e385..49fba719da4ca 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt @@ -18,6 +18,7 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice") placeholder disabled preferred_choices help help_attr + help_html inherit_data label label_attr diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json index e36dadf31fefb..49fcd8bd1335e 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json @@ -18,6 +18,7 @@ "error_bubbling", "help", "help_attr", + "help_html", "inherit_data", "label", "label_attr", diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt index 560d9c25d78c2..732c0d2f7c413 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt @@ -20,6 +20,7 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form") error_bubbling help help_attr + help_html inherit_data label label_attr