function DateFormatter::dateFormat

Same name in other branches
  1. 9 core/lib/Drupal/Core/Datetime/DateFormatter.php \Drupal\Core\Datetime\DateFormatter::dateFormat()
  2. 10 core/lib/Drupal/Core/Datetime/DateFormatter.php \Drupal\Core\Datetime\DateFormatter::dateFormat()
  3. 11.x core/lib/Drupal/Core/Datetime/DateFormatter.php \Drupal\Core\Datetime\DateFormatter::dateFormat()

Loads the given format pattern for the given langcode.

Parameters

string $format: The machine name of the date format.

string $langcode: The langcode of the language to use.

Return value

\Drupal\Core\Datetime\DateFormatInterface|null The configuration entity for the date format in the given language for non-custom formats, NULL otherwise.

1 call to DateFormatter::dateFormat()
DateFormatter::format in core/lib/Drupal/Core/Datetime/DateFormatter.php
Formats a date, using a date type or a custom date format string.

File

core/lib/Drupal/Core/Datetime/DateFormatter.php, line 327

Class

DateFormatter
Provides a service to handle various date related functionality.

Namespace

Drupal\Core\Datetime

Code

protected function dateFormat($format, $langcode) {
    if (!isset($this->dateFormats[$format][$langcode])) {
        $original_language = $this->languageManager
            ->getConfigOverrideLanguage();
        $this->languageManager
            ->setConfigOverrideLanguage(new Language([
            'id' => $langcode,
        ]));
        $this->dateFormats[$format][$langcode] = $this->dateFormatStorage
            ->load($format);
        $this->languageManager
            ->setConfigOverrideLanguage($original_language);
    }
    return $this->dateFormats[$format][$langcode];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.