function Date::preRenderDate

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date::preRenderDate()
  2. 10 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date::preRenderDate()
  3. 11.x core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date::preRenderDate()

Adds form-specific attributes to a 'date' #type element.

Supports HTML5 types of 'date', 'datetime', 'datetime-local', and 'time'. Falls back to a plain textfield with JS datepicker support. Used as a sub-element by the datetime element type.

Parameters

array $element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes, #id, #name, #type, #min, #max, #step, #value, #size. The #name property will be sanitized before output. This is currently done by initializing Drupal\Core\Template\Attribute with all the attributes.

Return value

array The $element with prepared variables ready for #theme 'input__date'.

File

core/lib/Drupal/Core/Render/Element/Date.php, line 89

Class

Date
Provides a form element for date selection.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderDate($element) {
    if (empty($element['#attributes']['type'])) {
        $element['#attributes']['type'] = 'date';
    }
    Element::setAttributes($element, [
        'id',
        'name',
        'type',
        'min',
        'max',
        'step',
        'value',
        'size',
    ]);
    static::setAttributes($element, [
        'form-' . $element['#attributes']['type'],
    ]);
    return $element;
}

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