8000 feature #27043 [Form][TwigBridge] Add help_attr (mpiot) · symfony/framework-bundle@f211c0c · GitHub
[go: up one dir, main page]

Skip to content

Commit f211c0c

Browse files
committed
feature #27043 [Form][TwigBridge] Add help_attr (mpiot)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Form][TwigBridge] Add help_attr | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Add help_attr to the form_help method. Commits ------- 42d54b73c3 Add help_attr
2 parents 8e522a8 + 0eaf095 commit f211c0c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php if (!empty($help)): ?>
2-
<p id="<?php echo $view->escape($id); ?>_help" class="help-text"><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($help, array(), $translation_domain) : $help); ?></p>
2+
<?php $help_attr['class'] = isset($help_attr['class']) ? trim($help_attr['class'].' help-text') : 'help-text'; ?>
3+
<p id="<?php echo $view->escape($id); ?>_help" <?php echo ' '.$view['form']->block($form, 'attributes', array('attr' => $help_attr)); ?>><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($help, array(), $translation_domain) : $help); ?></p>
34
<?php endif; ?>

Tests/Templating/Helper/FormHelperDivLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ public function testMoneyWidgetInIso()
9393
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
9494
}
9595

96+
public function testHelpAttr()
97+
{
98+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
99+
'help' => 'Help text test!',
100+
'help_attr' => array(
101+
'class' => 'class-test',
102+
),
103+
));
104+
$view = $form->createView();
105+
$html = $this->renderHelp($view);
106+
107+
$this->assertMatchesXpath($html,
108+
'/p
109+
[@id="name_help"]
110+
[@class="class-test help-text"]
111+
[.="[trans]Help text test![/trans]"]
112+
'
113+
);
114+
}
115+
96116
protected function renderForm(FormView $view, array $vars = array())
97117
{
98118
return (string) $this->engine->get('form')->form($view, $vars);

Tests/Templating/Helper/FormHelperTableLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
5151
$this->assertSame('<form name="form" method="get" action="0">', $html);
5252
}
5353

54+
public function testHelpAttr()
55+
{
56+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
57+
'help' => 'Help text test!',
58+
'help_attr' => array(
59+
'class' => 'class-test',
60+
),
61+
));
62+
$view = $form->createView();
63+
$html = $this->renderHelp($view);
64+
65+
$this->assertMatchesXpath($html,
66+
'/p
67+
[@id="name_help"]
68+
[@class="class-test help-text"]
69+
[.="[trans]Help text test![/trans]"]
70+
'
71+
);
72+
}
73+
5474
protected function getExtensions()
5575
{
5676
// should be moved to the Form component once absolute file paths are supported

0 commit comments

Comments
 (0)
0