feature #15301 [Form][Type Date/Time] added choice_translation_domain option. (aitboudad)
This PR was squashed before being merged into the 2.8 branch (closes #15301).
Discussion
----------
[Form][Type Date/Time] added choice_translation_domain option.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #15222 and #15298
| License | MIT
- [x] add test
Commits
-------
1f3af26
[Form][Type Date/Time] added choice_translation_domain option.
This commit is contained in:
commit
3909460c04
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
2.8.0
|
2.8.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* added option "choice_translation_domain" to DateType, TimeType and DateTimeType.
|
||||||
* deprecated option "read_only" in favor of "attr['readonly']"
|
* deprecated option "read_only" in favor of "attr['readonly']"
|
||||||
* added the html5 "range" FormType
|
* added the html5 "range" FormType
|
||||||
* deprecated the "cascade_validation" option in favor of setting "constraints"
|
* deprecated the "cascade_validation" option in favor of setting "constraints"
|
||||||
|
@ -116,6 +116,7 @@ class DateTimeType extends AbstractType
|
|||||||
'days',
|
'days',
|
||||||
'empty_value',
|
'empty_value',
|
||||||
'placeholder',
|
'placeholder',
|
||||||
|
'choice_translation_domain',
|
||||||
'required',
|
'required',
|
||||||
'translation_domain',
|
'translation_domain',
|
||||||
'html5',
|
'html5',
|
||||||
@ -131,6 +132,7 @@ class DateTimeType extends AbstractType
|
|||||||
'with_seconds',
|
'with_seconds',
|
||||||
'empty_value',
|
'empty_value',
|
||||||
'placeholder',
|
'placeholder',
|
||||||
|
'choice_translation_domain',
|
||||||
'required',
|
'required',
|
||||||
'translation_domain',
|
'translation_domain',
|
||||||
'html5',
|
'html5',
|
||||||
@ -245,6 +247,7 @@ class DateTimeType extends AbstractType
|
|||||||
$resolver->setDefined(array(
|
$resolver->setDefined(array(
|
||||||
'empty_value', // deprecated
|
'empty_value', // deprecated
|
||||||
'placeholder',
|
'placeholder',
|
||||||
|
'choice_translation_domain',
|
||||||
'years',
|
'years',
|
||||||
'months',
|
'months',
|
||||||
'days',
|
'days',
|
||||||
|
@ -94,10 +94,13 @@ class DateType extends AbstractType
|
|||||||
// Only pass a subset of the options to children
|
// Only pass a subset of the options to children
|
||||||
$yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
|
$yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
|
||||||
$yearOptions['placeholder'] = $options['placeholder']['year'];
|
$yearOptions['placeholder'] = $options['placeholder']['year'];
|
||||||
|
$yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
|
||||||
$monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
|
$monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
|
||||||
$monthOptions['placeholder'] = $options['placeholder']['month'];
|
$monthOptions['placeholder'] = $options['placeholder']['month'];
|
||||||
|
$monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month'];
|
||||||
$dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
|
$dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
|
||||||
$dayOptions['placeholder'] = $options['placeholder']['day'];
|
$dayOptions['placeholder'] = $options['placeholder']['day'];
|
||||||
|
$dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append generic carry-along options
|
// Append generic carry-along options
|
||||||
@ -205,6 +208,23 @@ class DateType extends AbstractType
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$choiceTranslationDomainNormalizer = function (Options $options, $choiceTranslationDomain) {
|
||||||
|
if (is_array($choiceTranslationDomain)) {
|
||||||
|
$default = false;
|
||||||
|
|
||||||
|
return array_replace(
|
||||||
|
array('year' => $default, 'month' => $default, 'day' => $default),
|
||||||
|
$choiceTranslationDomain
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'year' => $choiceTranslationDomain,
|
||||||
|
'month' => $choiceTranslationDomain,
|
||||||
|
'day' => $choiceTranslationDomain,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
$format = function (Options $options) {
|
$format = function (Options $options) {
|
||||||
return $options['widget'] === 'single_text' ? DateType::HTML5_FORMAT : DateType::DEFAULT_FORMAT;
|
return $options['widget'] === 'single_text' ? DateType::HTML5_FORMAT : DateType::DEFAULT_FORMAT;
|
||||||
};
|
};
|
||||||
@ -231,10 +251,12 @@ class DateType extends AbstractType
|
|||||||
// this option.
|
// this option.
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
|
'choice_translation_domain' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
|
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
|
||||||
|
|
||||||
$resolver->setAllowedValues('input', array(
|
$resolver->setAllowedValues('input', array(
|
||||||
'datetime',
|
'datetime',
|
||||||
|
@ -69,6 +69,7 @@ class TimeType extends AbstractType
|
|||||||
// Only pass a subset of the options to children
|
// Only pass a subset of the options to children
|
||||||
$hourOptions['choices'] = $hours;
|
$hourOptions['choices'] = $hours;
|
||||||
$hourOptions['placeholder'] = $options['placeholder']['hour'];
|
$hourOptions['placeholder'] = $options['placeholder']['hour'];
|
||||||
|
$hourOptions['choice_translation_domain'] = $options['choice_translation_domain']['hour'];
|
||||||
|
|
||||||
if ($options['with_minutes']) {
|
if ($options['with_minutes']) {
|
||||||
foreach ($options['minutes'] as $minute) {
|
foreach ($options['minutes'] as $minute) {
|
||||||
@ -77,6 +78,7 @@ class TimeType extends AbstractType
|
|||||||
|
|
||||||
$minuteOptions['choices'] = $minutes;
|
$minuteOptions['choices'] = $minutes;
|
||||||
$minuteOptions['placeholder'] = $options['placeholder']['minute'];
|
$minuteOptions['placeholder'] = $options['placeholder']['minute'];
|
||||||
|
$minuteOptions['choice_translation_domain'] = $options['choice_translation_domain']['minute'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['with_seconds']) {
|
if ($options['with_seconds']) {
|
||||||
@ -88,6 +90,7 @@ class TimeType extends AbstractType
|
|||||||
|
|
||||||
$secondOptions['choices'] = $seconds;
|
$secondOptions['choices'] = $seconds;
|
||||||
$secondOptions['placeholder'] = $options['placeholder']['second'];
|
$secondOptions['placeholder'] = $options['placeholder']['second'];
|
||||||
|
$secondOptions['choice_translation_domain'] = $options['choice_translation_domain']['second'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append generic carry-along options
|
// Append generic carry-along options
|
||||||
@ -194,6 +197,23 @@ class TimeType extends AbstractType
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$choiceTranslationDomainNormalizer = function (Options $options, $choiceTranslationDomain) {
|
||||||
|
if (is_array($choiceTranslationDomain)) {
|
||||||
|
$default = false;
|
||||||
|
|
||||||
|
return array_replace(
|
||||||
|
array('hour' => $default, 'minute' => $default, 'second' => $default),
|
||||||
|
$choiceTranslationDomain
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'hour' => $choiceTranslationDomain,
|
||||||
|
'minute' => $choiceTranslationDomain,
|
||||||
|
'second' => $choiceTranslationDomain,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'hours' => range(0, 23),
|
'hours' => range(0, 23),
|
||||||
'minutes' => range(0, 59),
|
'minutes' => range(0, 59),
|
||||||
@ -217,10 +237,12 @@ class TimeType extends AbstractType
|
|||||||
// this option.
|
// this option.
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
|
'choice_translation_domain' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
|
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
|
||||||
|
|
||||||
$resolver->setAllowedValues('input', array(
|
$resolver->setAllowedValues('input', array(
|
||||||
'datetime',
|
'datetime',
|
||||||
|
@ -519,4 +519,57 @@ class DateTimeTypeTest extends TestCase
|
|||||||
$this->assertSame(array(), iterator_to_array($form['time']->getErrors()));
|
$this->assertSame(array(), iterator_to_array($form['time']->getErrors()));
|
||||||
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
|
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||||
|
'with_seconds' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
|
||||||
|
$this->assertFalse($view['date']['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['date']['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['date']['day']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['time']['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['time']['second']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||||
|
'choice_translation_domain' => 'messages',
|
||||||
|
'with_seconds' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('messages', $view['date']['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['date']['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['date']['day']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['time']['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['time']['minute']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['time']['second']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||||
|
'choice_translation_domain' => array(
|
||||||
|
'year' => 'foo',
|
||||||
|
'month' => 'test',
|
||||||
|
'hour' => 'foo',
|
||||||
|
'second' => 'test',
|
||||||
|
),
|
||||||
|
'with_seconds' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('foo', $view['date']['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('test', $view['date']['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['date']['day']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('foo', $view['time']['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('test', $view['time']['second']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -950,4 +950,41 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals($listChoices, $view['year']->vars['choices']);
|
$this->assertEquals($listChoices, $view['year']->vars['choices']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertFalse($view['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['day']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||||
|
'choice_translation_domain' => 'messages',
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('messages', $view['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['day']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||||
|
'choice_translation_domain' => array(
|
||||||
|
'year' => 'foo',
|
||||||
|
'day' => 'test',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('foo', $view['year']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['month']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('test', $view['day']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,4 +736,42 @@ class TimeTypeTest extends TestCase
|
|||||||
'seconds' => 'bad value',
|
'seconds' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType');
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertFalse($view['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||||
|
'choice_translation_domain' => 'messages',
|
||||||
|
'with_seconds' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('messages', $view['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['minute']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('messages', $view['second']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||||
|
'choice_translation_domain' => array(
|
||||||
|
'hour' => 'foo',
|
||||||
|
'second' => 'test',
|
||||||
|
),
|
||||||
|
'with_seconds' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertSame('foo', $view['hour']->vars['choice_translation_domain']);
|
||||||
|
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
|
||||||
|
$this->assertSame('test', $view['second']->vars['choice_translation_domain']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user