[Form] Replace methods in ChoiceView by public properties (PHP +100ms, Twig +400ms)
This commit is contained in:
parent
d072f35ea0
commit
400c95bb4d
|
@ -2,10 +2,10 @@
|
|||
<?php if ($view['form']->isChoiceGroup($choice)): ?>
|
||||
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
|
||||
<?php foreach ($choice as $nested_choice): ?>
|
||||
<option value="<?php echo $view->escape($nested_choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($nested_choice->getLabel(), array(), $translation_domain)) ?></option>
|
||||
<option value="<?php echo $view->escape($nested_choice->value) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($nested_choice->label, array(), $translation_domain)) ?></option>
|
||||
<?php endforeach ?>
|
||||
</optgroup>
|
||||
<?php else: ?>
|
||||
<option value="<?php echo $view->escape($choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->getLabel(), array(), $translation_domain)) ?></option>
|
||||
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->label, array(), $translation_domain)) ?></option>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
|
|
@ -226,8 +226,8 @@ class ChoiceType extends AbstractType
|
|||
$this->addSubForms($builder, $choiceView, $options);
|
||||
} else {
|
||||
$choiceOpts = array(
|
||||
'value' => $choiceView->getValue(),
|
||||
'label' => $choiceView->getLabel(),
|
||||
'value' => $choiceView->value,
|
||||
'label' => $choiceView->label,
|
||||
'translation_domain' => $options['translation_domain'],
|
||||
);
|
||||
|
||||
|
|
|
@ -23,14 +23,14 @@ class ChoiceView
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $value;
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* The label displayed to humans.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Creates a new ChoiceView.
|
||||
|
@ -43,24 +43,4 @@ class ChoiceView
|
|||
$this->value = $value;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the choice value.
|
||||
*
|
||||
* @return string The view representation of the choice.
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the choice label.
|
||||
*
|
||||
* @return string The label displayed to humans.
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ class FormRenderer implements FormRendererInterface
|
|||
public function isChoiceSelected(FormView $view, ChoiceView $choice)
|
||||
{
|
||||
$value = $view->vars['value'];
|
||||
$choiceValue = $choice->getValue();
|
||||
$choiceValue = $choice->value;
|
||||
|
||||
if (is_array($value)) {
|
||||
return false !== array_search($choiceValue, $value, true);
|
||||
|
|
|
@ -38,7 +38,7 @@ class CountryTypeTest extends LocalizedTestCase
|
|||
$choices = $view->vars['choices'];
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
if ('ZZ' === $choice->getValue()) {
|
||||
if ('ZZ' === $choice->value) {
|
||||
$this->fail('Should not contain choice "ZZ"');
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue