You are here

public function Datetime::getInfo in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Datetime/Element/Datetime.php \Drupal\Core\Datetime\Element\Datetime::getInfo()

Returns the element properties for this element.

Return value

array An array of element properties. See \Drupal\Core\Render\ElementInfoManagerInterface::getInfo() for documentation of the standard properties of all elements, and the return value format.

Overrides ElementInterface::getInfo

File

core/lib/Drupal/Core/Datetime/Element/Datetime.php, line 31

Class

Datetime
Provides a datetime element.

Namespace

Drupal\Core\Datetime\Element

Code

public function getInfo() {
  $date_format = '';
  $time_format = '';

  // Date formats cannot be loaded during install or update.
  if (!defined('MAINTENANCE_MODE')) {
    if ($date_format_entity = DateFormat::load('html_date')) {

      /** @var \Drupal\Core\Datetime\DateFormatInterface $date_format_entity */
      $date_format = $date_format_entity
        ->getPattern();
    }
    if ($time_format_entity = DateFormat::load('html_time')) {

      /** @var \Drupal\Core\Datetime\DateFormatInterface $time_format_entity */
      $time_format = $time_format_entity
        ->getPattern();
    }
  }
  $class = static::class;

  // Note that since this information is cached, the #date_timezone property
  // is not set here, as this needs to vary potentially by-user.
  return [
    '#input' => TRUE,
    '#element_validate' => [
      [
        $class,
        'validateDatetime',
      ],
    ],
    '#process' => [
      [
        $class,
        'processDatetime',
      ],
      [
        $class,
        'processAjaxForm',
      ],
      [
        $class,
        'processGroup',
      ],
    ],
    '#pre_render' => [
      [
        $class,
        'preRenderGroup',
      ],
    ],
    '#theme' => 'datetime_form',
    '#theme_wrappers' => [
      'datetime_wrapper',
    ],
    '#date_date_format' => $date_format,
    '#date_date_element' => 'date',
    '#date_date_callbacks' => [],
    '#date_time_format' => $time_format,
    '#date_time_element' => 'time',
    '#date_time_callbacks' => [],
    '#date_year_range' => '1900:2050',
    '#date_increment' => 1,
  ];
}