function Checkbox::preRenderCheckbox

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Checkbox.php \Drupal\Core\Render\Element\Checkbox::preRenderCheckbox()
  2. 8.9.x core/lib/Drupal/Core/Render/Element/Checkbox.php \Drupal\Core\Render\Element\Checkbox::preRenderCheckbox()
  3. 11.x core/lib/Drupal/Core/Render/Element/Checkbox.php \Drupal\Core\Render\Element\Checkbox::preRenderCheckbox()

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

Parameters

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

Return value

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

File

core/lib/Drupal/Core/Render/Element/Checkbox.php, line 94

Class

Checkbox
Provides a form element for a single checkbox.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderCheckbox($element) {
    $element['#attributes']['type'] = 'checkbox';
    Element::setAttributes($element, [
        'id',
        'name',
        '#return_value' => 'value',
    ]);
    // Unchecked checkbox has #value of integer 0.
    if (!empty($element['#checked'])) {
        $element['#attributes']['checked'] = 'checked';
    }
    static::setAttributes($element, [
        'form-checkbox',
    ]);
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.