diff --git a/core/includes/form.inc b/core/includes/form.inc index 87f8edf..794e779 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1153,6 +1153,33 @@ function theme_date($variables) { } /** + * 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. Used as a sub-element by the datetime + * element type. + * + * @param 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. + * + * 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 array + * The $element with prepared variables ready for #theme 'input__date'. + */ +function form_pre_render_date($element) { + $element['#attributes']['type'] = 'date'; + element_set_attributes($element, array('id', 'name', 'min', 'max', 'step', 'value', 'size')); + _form_set_attributes($element, array('form-date')); + + return $element; +} + +/** * Sets the value for a weight element, with zero as a default. */ function weight_value(&$form) { diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7fd8de4..2c69053 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2672,9 +2672,6 @@ function drupal_common_theme() { 'radios' => array( 'render element' => 'element', ), - 'date' => array( - 'render element' => 'element', - ), 'checkboxes' => array( 'render element' => 'element', ), diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c0b0f02..34e13b4 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -483,7 +483,8 @@ function system_element_info() { ); $types['date'] = array( '#input' => TRUE, - '#theme' => 'date', + '#theme' => 'input__date', + '#pre_render' => array('form_pre_render_date'), '#theme_wrappers' => array('form_element'), ); $types['file'] = array(