function datetime_html5_format

Retrieves the right format for a HTML5 date element.

The format is important because these elements will not work with any other format.

Parameters

string $part: The type of element format to retrieve.

string $element: The $element to assess.

Return value

string Returns the right format for the type of element, or the original format if this is not a HTML5 element.

3 calls to datetime_html5_format()
datetime_datetime_form_process in drupal/core/modules/datetime/datetime.module
Expands a #datetime element type into date and/or time elements.
datetime_datetime_validate in drupal/core/modules/datetime/datetime.module
Validation callback for a datetime element.
form_type_datetime_value in drupal/core/modules/datetime/datetime.module
Value callback for a datetime element.

File

drupal/core/modules/datetime/datetime.module, line 704
Field hooks to implement a simple datetime field.

Code

function datetime_html5_format($part, $element) {
  $format_type = datetime_default_format_type();
  switch ($part) {
    case 'date':
      switch ($element['#date_date_element']) {
        case 'date':
          return config('system.date')
            ->get('formats.html_date.pattern.' . $format_type);
        case 'datetime':
        case 'datetime-local':
          return config('system.date')
            ->get('formats.html_datetime.pattern.' . $format_type);
        default:
          return $element['#date_date_format'];
      }
      break;
    case 'time':
      switch ($element['#date_time_element']) {
        case 'time':
          return config('system.date')
            ->get('formats.html_time.pattern.' . $format_type);
        default:
          return $element['#date_time_format'];
      }
      break;
  }
}