Skip to content

Commit 917067e

Browse files
committed
bug symfony#13647 [FrameworkBundle] Fix title and placeholder rendering in php form templates (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- [FrameworkBundle] Fix title and placeholder rendering in php form templates Small fix for rendering placeholder on widgets in php templates. | Q | A | | ------------- | --- | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Tests pass? | no | | Fixed tickets | - | | License | MIT | | Doc PR | - | This is a test case for symfony#13290, including a fix applied on 2.3, since that's the earliest supported branch the bug exist. In 2.6 the template is a bit different, and unfortunately I couldn't re-use symfony#13290's fix. When this is merged into 2.3, and then to 2.6 I think we can also merge symfony#13290. Commits ------- f82193d [FrameworkBundle] Fix title and placeholder rendering in php form templates.
2 parents 9a70bbb + f82193d commit 917067e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>" <?php endif ?>
77
<?php if ($pattern): ?>pattern="<?php echo $view->escape($pattern) ?>" <?php endif ?>
88
<?php foreach ($attr as $k => $v): ?>
9-
<?php printf('%s="%s" ', $view->escape($k), $view->escape(in_array($v, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
9+
<?php printf('%s="%s" ', $view->escape($k), $view->escape(in_array($k, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
1010
<?php endforeach; ?>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,4 +1898,18 @@ public function testStartTagWithExtraAttributes()
18981898

18991899
$this->assertSame('<form method="get" action="http://example.com/directory" class="foobar">', $html);
19001900
}
1901+
1902+
public function testTranslatedAttributes()
1903+
{
1904+
$view = $this->factory->createNamedBuilder('name', 'form')
1905+
->add('firstName', 'text', array('attr' => array('title' => 'Foo')))
1906+
->add('lastName', 'text', array('attr' => array('placeholder' => 'Bar')))
1907+
->getForm()
1908+
->createView();
1909+
1910+
$html = $this->renderForm($view);
1911+
1912+
$this->assertMatchesXpath($html, '/form//input[@title="[trans]Foo[/trans]"]');
1913+
$this->assertMatchesXpath($html, '/form//input[@placeholder="[trans]Bar[/trans]"]');
1914+
}
19011915
}

0 commit comments

Comments
 (0)