public static function WebformRadiosOther::valueCallback in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformRadiosOther.php \Drupal\webform\Element\WebformRadiosOther::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 WebformOtherBase::valueCallback
File
- src/
Element/ WebformRadiosOther.php, line 22
Class
- WebformRadiosOther
- Provides a webform element for radio buttons with an other option.
Namespace
Drupal\webform\ElementCode
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
// Remove 'webform_' prefix from type.
$type = str_replace('webform_', '', static::$type);
// Unset #default_value that is not a valid #option.
//
// This behavior is needed when a radios #default_value was previously set
// but now the radios are unchecked via conditional logic. This results in
// nothing being posted back to the server, and the #default_value is used
// which throws "An illegal choice has been detected." error.
if ($input && !isset($input[$type]) && isset($element['#default_value']) && !isset($element['#option'][$element['#default_value']])) {
unset($element['#default_value']);
}
return parent::valueCallback($element, $input, $form_state);
}