Purpose of (wrong?) datetime-attr in buildDateWithIsoAttribute

Created on 14 November 2019, about 5 years ago
Updated 7 September 2024, 4 months ago

I wanted to use the attribute as starting value for an ajax-load-more but #text and #attr differ with regard to timezones. As I'm not in UTC this doesn't work and I had to add a custom "correct" datetime-attribute to work with.

I wonder if anyone could explain the purpose of the datetime-attribute added to the render array in buildDateWithIsoAttribute?

  protected function buildDateWithIsoAttribute(DrupalDateTime $date) {
    // Create the ISO date in Universal Time.
    $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z';

    $this->setTimeZone($date);

    $build = [
      '#theme' => 'time',
      '#text' => $this->formatDate($date),
      '#html' => FALSE,
      '#attributes' => [
        'datetime' => $iso_date,
      ],
      '#cache' => [
        'contexts' => [
          'timezone',
        ],
      ],
    ];

    return $build;
  }
πŸ’¬ Support request
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
DatetimeΒ  β†’

Last updated 6 days ago

Created by

πŸ‡©πŸ‡ͺGermany tasc Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024