[FrameworkBundle] Fix title and placeholder rendering in php form templates.

This commit is contained in:
Jakub Zalas 2015-02-10 17:14:04 +00:00
parent 9a70bbbdb2
commit f82193db99
2 changed files with 15 additions and 1 deletions

View File

@ -6,5 +6,5 @@ name="<?php echo $view->escape($full_name) ?>"
<?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; ?>

View File

@ -1898,4 +1898,18 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
$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]"]');
}
}