Skip to content

Commit

Permalink
[FrameworkBundle] Fix title and placeholder rendering in php form tem…
Browse files Browse the repository at this point in the history
…plates.
  • Loading branch information
jakzal committed Feb 10, 2015
1 parent 9a70bbb commit f82193d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -6,5 +6,5 @@
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>" <?php endif ?>
<?php if ($pattern): ?>pattern="<?php echo $view->escape($pattern) ?>" <?php endif ?>
<?php foreach ($attr as $k => $v): ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape(in_array($v, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape(in_array($k, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
<?php endforeach; ?>
14 changes: 14 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -1898,4 +1898,18 @@ public function testStartTagWithExtraAttributes()

$this->assertSame('<form method="get" action="http://example.com/directory" class="foobar">', $html);
}

public function testTranslatedAttributes()
{
$view = $this->factory->createNamedBuilder('name', 'form')
->add('firstName', 'text', array('attr' => array('title' => 'Foo')))
->add('lastName', 'text', array('attr' => array('placeholder' => 'Bar')))
->getForm()
->createView();

$html = $this->renderForm($view);

$this->assertMatchesXpath($html, '/form//input[@title="[trans]Foo[/trans]"]');
$this->assertMatchesXpath($html, '/form//input[@placeholder="[trans]Bar[/trans]"]');
}
}

0 comments on commit f82193d

Please sign in to comment.