formatExample example

$element['#tree'] = TRUE;

    if ($element['#date_date_element'] != 'none') {

      $date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
      $date_value = !empty($date) ? $date->format($date_format$format_settings) : $element['#value']['date'];

      // Creating format examples on every individual date item is messy, and       // placeholders are invalid for HTML5 date and datetime, so an example       // format is appended to the title to appear in tooltips.       $extra_attributes = [
        'title' => t('Date (e.g. @format)', ['@format' => static::formatExample($date_format)]),
        'type' => $element['#date_date_element'],
      ];

      // Adds the HTML5 date attributes.       if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
        $html5_min = clone($date);
        $range = static::datetimeRangeYears($element['#date_year_range']$date);
        $html5_min->setDate($range[0], 1, 1)->setTime(0, 0, 0);
        $html5_max = clone($date);
        $html5_max->setDate($range[1], 12, 31)->setTime(23, 59, 59);

        
$time_format = DateFormat::load('html_time')->getPattern();
    $default_value = isset($items[$delta]->value) ? DrupalDateTime::createFromTimestamp($items[$delta]->value) : '';
    $element['value'] = $element + [
      '#type' => 'datetime',
      '#default_value' => $default_value,
      '#date_year_range' => '1902:2037',
    ];

    $element['value']['#description'] = $element['#description'] !== ''
    ? $element['#description']
    : $this->t('Format: %format. Leave blank to use the time of form submission.',
    ['%format' => Datetime::formatExample($date_format . ' ' . $time_format)]);

    return $element;
  }

  /** * {@inheritdoc} */
  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach ($values as &$item) {
      // @todo The structure is different whether access is denied or not, to       // be fixed in https://www.drupal.org/node/2326533.
Home | Imprint | This part of the site doesn't use cookies.