Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e133be

Browse filesBrowse files
committed
feature #41717 Allow TranslatableMessage object in form option 'help' (scuben)
This PR was merged into the 5.4 branch. Discussion ---------- Allow TranslatableMessage object in form option 'help' | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> This PR allows the use of `TranslatableMessage` (or `t(...)`) for a help option the same way the label option already supports this. <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> Commits ------- 44461f1 Allow to pass TranslatableMessage objects to the help option
2 parents 3c48a52 + 44461f1 commit 0e133be
Copy full SHA for 0e133be

File tree

3 files changed

+38
-1
lines changed
Filter options

3 files changed

+38
-1
lines changed

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.4
5+
---
6+
7+
* Allow to pass `TranslatableMessage` objects to the `help` option
8+
49
5.3
510
---
611

‎src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FormType.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\OptionsResolver\OptionsResolver;
2626
use Symfony\Component\PropertyAccess\PropertyAccess;
2727
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
28+
use Symfony\Component\Translation\TranslatableMessage;
2829

2930
class FormType extends BaseType
3031
{
@@ -226,7 +227,7 @@ public function configureOptions(OptionsResolver $resolver)
226227
$resolver->setAllowedTypes('label_attr', 'array');
227228
$resolver->setAllowedTypes('action', 'string');
228229
$resolver->setAllowedTypes('upload_max_size_message', ['callable']);
229-
$resolver->setAllowedTypes('help', ['string', 'null']);
230+
$resolver->setAllowedTypes('help', ['string', 'null', TranslatableMessage::class]);
230231
$resolver->setAllowedTypes('help_attr', 'array');
231232
$resolver->setAllowedTypes('help_html', 'bool');
232233
$resolver->setAllowedTypes('is_empty_callback', ['null', 'callable']);

‎src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\FormView;
2020
use Symfony\Component\Form\Test\FormIntegrationTestCase;
2121
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
22+
use Symfony\Component\Translation\TranslatableMessage;
2223

2324
abstract class AbstractLayoutTest extends FormIntegrationTestCase
2425
{
@@ -2668,6 +2669,36 @@ public function testHelpWithTranslationParameters()
26682669
);
26692670
}
26702671

2672+
public function testLabelWithTranslatableMessage()
2673+
{
2674+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
2675+
'label' => new TranslatableMessage('foo'),
2676+
]);
2677+
$html = $this->renderLabel($form->createView());
2678+
2679+
$this->assertMatchesXpath($html,
2680+
'/label
2681+
[@for="name"]
2682+
[.="[trans]foo[/trans]"]
2683+
'
2684+
);
2685+
}
2686+
2687+
public function testHelpWithTranslatableMessage()
2688+
{
2689+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
2690+
'help' => new TranslatableMessage('foo'),
2691+
]);
2692+
$html = $this->renderHelp($form->createView());
2693+
2694+
$this->assertMatchesXpath($html,
2695+
'/*
2696+
[@id="name_help"]
2697+
[.="[trans]foo[/trans]"]
2698+
'
2699+
);
2700+
}
2701+
26712702
public function testAttributesWithTranslationParameters()
26722703
{
26732704
$this->requiresFeatureSet(403);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.