Skip to content

Commit

Permalink
[Form] Added the ability to specify the translation domain
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Oct 10, 2011
1 parent ca2962e commit 6e4269f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
Expand Up @@ -56,6 +56,7 @@ public function buildForm(FormBuilder $builder, array $options)
->setAttribute('attr', $options['attr'] ?: array())
->setAttribute('invalid_message', $options['invalid_message'])
->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])
->setAttribute('translation_domain', $options['translation_domain'])
->setData($options['data'])
->addValidator(new DefaultValidator())
;
Expand Down Expand Up @@ -103,6 +104,7 @@ public function buildView(FormView $view, FormInterface $form)
->set('multipart', false)
->set('attr', $form->getAttribute('attr'))
->set('types', $types)
->set('translation_domain', $form->getAttribute('translation_domain'))
;
}

Expand All @@ -127,6 +129,7 @@ public function getDefaultOptions(array $options)
'attr' => array(),
'invalid_message' => 'This value is not valid',
'invalid_message_parameters' => array(),
'translation_domain' => 'messages',
);

$class = isset($options['data_class']) ? $options['data_class'] : null;
Expand Down
Expand Up @@ -151,6 +151,22 @@ public function testPassMaxLengthToView()
$this->assertSame(10, $view->get('max_length'));
}

public function testPassTranslationDomainToView()
{
$form = $this->factory->create('field', null, array('translation_domain' => 'test'));
$view = $form->createView();

$this->assertSame('test', $view->get('translation_domain'));
}

public function testDefaultTranslationDomain()
{
$form = $this->factory->create('field');
$view = $form->createView();

$this->assertSame('messages', $view->get('translation_domain'));
}

public function testBindWithEmptyDataCreatesObjectIfClassAvailable()
{
$form = $this->factory->create('form', null, array(
Expand Down

0 comments on commit 6e4269f

Please sign in to comment.