You are here

public static function WebformTime::preRenderWebformTime in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformTime.php \Drupal\webform\Element\WebformTime::preRenderWebformTime()

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

Parameters

array $element: An associative array containing the properties of the element.

Return value

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

File

src/Element/WebformTime.php, line 177

Class

WebformTime
Provides a webform element for time selection.

Namespace

Drupal\webform\Element

Code

public static function preRenderWebformTime(array $element) {
  if (!empty($element['#timepicker'])) {

    // Render simple text field that is converted to timepicker.
    $element['#attributes']['type'] = 'text';

    // Apply #time_format to #default_value.
    if (!empty($element['#value']) && !empty($element['#default_value']) && $element['#value'] === $element['#default_value']) {
      $element['#value'] = static::formatTime($element['#attributes']['data-webform-time-format'], strtotime($element['#value']));
    }
  }
  else {
    $element['#attributes']['type'] = 'time';
  }
  Element::setAttributes($element, [
    'id',
    'name',
    'type',
    'value',
    'size',
    'maxlength',
    'min',
    'max',
    'step',
  ]);
  static::setAttributes($element, [
    'form-time',
    'webform-time',
  ]);
  return $element;
}