public static function Dropdown::valueCallback in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.2 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.3 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.4 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.5 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.6 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.7 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 8.8 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 10.3.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 10.0.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 10.1.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
- 10.2.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::valueCallback()
Determines how user input is mapped to an element's #value property.
Parameters
array $element: An associative array containing the properties of the element.
mixed $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
mixed The value to assign to the element.
Overrides FormElement::valueCallback
File
- modules/
custom/ dropdown/ src/ Element/ Dropdown.php, line 92
Class
- Dropdown
- Provides an dropdown element.
Namespace
Drupal\dropdown\ElementCode
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
if ($input !== FALSE) {
// When there's user input (including NULL), return it as the value.
// However, if NULL is submitted, FormBuilder::handleInputElement() will
// apply the default value, and we want that validated against #options
// unless it's empty. (An empty #default_value, such as NULL or FALSE, can
// be used to indicate that no radio button is selected by default.)
if (!isset($input) && !empty($element['#default_value'])) {
$element['#needs_validation'] = TRUE;
}
return $input;
}
else {
// For default value handling, simply return #default_value. Additionally,
// for a NULL default value, set #has_garbage_value to prevent
// FormBuilder::handleInputElement() converting the NULL to an empty
// string, so that code can distinguish between nothing selected and the
// selection of a radio button whose value is an empty string.
$value = isset($element['#default_value']) ? $element['#default_value'] : NULL;
if (!isset($value)) {
$element['#has_garbage_value'] = TRUE;
}
return $value;
}
}