You are here

public static function Radio::preRenderRadio in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Render/Element/Radio.php \Drupal\Core\Render\Element\Radio::preRenderRadio()

Prepares a #type 'radio' render element for input.html.twig.

Parameters

array $element: An associative array containing the properties of the element. Properties used: #required, #return_value, #value, #attributes, #title, #description.

Note: The input "name" attribute needs to be sanitized before output, which is currently done by initializing Drupal\Core\Template\Attribute with all the attributes.

Return value

array The $element with prepared variables ready for input.html.twig.

File

core/lib/Drupal/Core/Render/Element/Radio.php, line 60
Contains \Drupal\Core\Render\Element\Radio.

Class

Radio
Provides a form element for a single radio button.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderRadio($element) {
  $element['#attributes']['type'] = 'radio';
  Element::setAttributes($element, array(
    'id',
    'name',
    '#return_value' => 'value',
  ));
  if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_value']) {
    $element['#attributes']['checked'] = 'checked';
  }
  static::setAttributes($element, array(
    'form-radio',
  ));
  return $element;
}