-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Renamed the option "empty_value" to "placeholder" #6475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
<?php if ($required): ?>required="required" <?php endif ?> | ||
<?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 if ($placeholder): ?>placeholder="<?php echo $view->escape($view['translator']->trans($placeholder, array(), $translation_domain)) ?>" <?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($v, array('title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $view->escape('title' === $v ? $view['translator]'... |
||
<?php endforeach; ?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |
// Check if the choices already contain the empty value | ||
// Only add the empty value option if this is not the case | ||
if (0 === count($options['choice_list']->getIndicesForValues(array('')))) { | ||
$view->vars['empty_value'] = $options['empty_value']; | ||
$view->vars['empty_value'] = $options['placeholder']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the variable |
||
} | ||
|
||
if ($options['multiple'] && !$options['expanded']) { | ||
|
@@ -165,21 +165,24 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
return ''; | ||
}; | ||
|
||
$emptyValue = function (Options $options) { | ||
return $options['required'] ? null : ''; | ||
$placeholderValue = function (Options $options) { | ||
// BC until Symfony 2.3 | ||
return null !== $options['empty_value'] | ||
? $options['empty_value'] | ||
: ($options['required'] ? null : ''); | ||
}; | ||
|
||
$emptyValueNormalizer = function (Options $options, $emptyValue) { | ||
$placeholderValueNormalizer = function (Options $options, $placeholderValue) { | ||
if ($options['multiple'] || $options['expanded']) { | ||
// never use an empty value for these cases | ||
return null; | ||
} elseif (false === $emptyValue) { | ||
} elseif (false === $placeholderValue) { | ||
// an empty value should be added but the user decided otherwise | ||
return null; | ||
} | ||
|
||
// empty value has been set explicitly | ||
return $emptyValue; | ||
return $placeholderValue; | ||
}; | ||
|
||
$compound = function (Options $options) { | ||
|
@@ -193,7 +196,9 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
'choices' => array(), | ||
'preferred_choices' => array(), | ||
'empty_data' => $emptyData, | ||
'empty_value' => $emptyValue, | ||
'placeholder' => $placeholderValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "placeholder" option should be removed here and added to |
||
// Deprecated empty_value option | ||
'empty_value' => null, | ||
'error_bubbling' => false, | ||
'compound' => $compound, | ||
// The view data is always a string, even if the "data" option | ||
|
@@ -203,7 +208,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
)); | ||
|
||
$resolver->setNormalizers(array( | ||
'empty_value' => $emptyValueNormalizer, | ||
'placeholder' => $placeholderValueNormalizer, | ||
)); | ||
|
||
$resolver->setAllowedTypes(array( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.