commit 1aa8b6ed9c3e96d07a71fc2d22c4db77f18ae8e9 Author: Joel Pittet Date: Fri Jul 31 22:32:46 2015 -0700 no need for value callback diff --git a/core/lib/Drupal/Core/Render/Element/Radio.php b/core/lib/Drupal/Core/Render/Element/Radio.php index 5a7996f..022b5c2 100644 --- a/core/lib/Drupal/Core/Render/Element/Radio.php +++ b/core/lib/Drupal/Core/Render/Element/Radio.php @@ -45,38 +45,6 @@ public function getInfo() { } /** - * {@inheritdoc} - */ - public static function valueCallback(&$element, $input, FormStateInterface $form_state) { - if ($input === FALSE) { - // Use #default_value as the default value of a radio, except change - // NULL to 0, because FormBuilder::handleInputElement() would otherwise - // replace NULL with empty string, but an empty string is a potentially - // valid value for a checked radio. - return isset($element['#default_value']) ? $element['#default_value'] : 0; - } - else { - // Checked radios are submitted with a value (possibly '0' or ''): - // http://www.w3.org/TR/html401/interact/forms.html#successful-controls. - // For checked radios, browsers submit the string version of - // #return_value, but we return the original #return_value. For unchecked - // radios, browsers submit nothing at all, but - // FormBuilder::handleInputElement() detects this, and calls this - // function with $input=NULL. Returning NULL from a value callback means - // to use the default value, which is not what is wanted when an unchecked - // radio is submitted, so we use integer 0 as the value indicating an - // unchecked radio. Therefore, modules must not use integer 0 as a - // #return_value, as doing so results in the radio always being treated - // as unchecked. The string '0' is allowed for #return_value. The most - // common use-case for setting #return_value to either 0 or '0' is for the - // first option within a 0-indexed array of radios, and for this, - // \Drupal\Core\Render\Element\Checkboxes::processCheckboxes() uses the - // string rather than the integer. - return isset($input) ? $element['#return_value'] : 0; - } - } - - /** * Prepares a #type 'radio' render element for input.html.twig. * * @param array $element @@ -95,7 +63,7 @@ public static function preRenderRadio($element) { $element['#attributes']['type'] = 'radio'; Element::setAttributes($element, array('id', 'name', '#return_value' => 'value')); - // Unchecked radio has #value of integer 0. + // Unchecked radio has #value of FALSE. if (!empty($element['#checked'])) { $element['#attributes']['checked'] = 'checked'; } @@ -112,9 +80,9 @@ public static function processRadio(&$element, FormStateInterface $form_state, & $return_value = $element['#return_value']; // On form submission, the #value of an available and enabled checked // radio is #return_value, and the #value of an available and enabled - // unchecked radio is integer 0. On not submitted forms, and for + // unchecked radio is FALSE. On not submitted forms, and for // radios with #access=FALSE or #disabled=TRUE, the #value is - // #default_value (integer 0 if #default_value is NULL). Most of the time, + // #default_value (FALSE if #default_value is NULL). Most of the time, // a string comparison of #value and #return_value is sufficient for // determining the "checked" state, but a value of TRUE always means checked // (even if #return_value is 'foo'), and a value of FALSE or integer 0