diff --git a/core/core.services.yml b/core/core.services.yml index a827835..e383fde 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -555,7 +555,7 @@ services: arguments: ['@module_handler'] date: class: Drupal\Core\Datetime\Date - arguments: ['@entity.manager', '@language_manager'] + arguments: ['@entity.manager', '@language_manager', '@config.factory'] feed.bridge.reader: class: Drupal\Component\Bridge\ZfExtensionManagerSfContainer calls: diff --git a/core/includes/config.inc b/core/includes/config.inc index c7362a2..2857c68 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -179,19 +179,6 @@ function config_context_leave() { } /** - * Gets the current config context. - * - * @see config_context_enter() - * @see config_context_leave() - * @see \Drupal\Core\Config\ConfigFactory - */ -function config_context() { - drupal_container() - ->get('config.factory') - ->getContext(); -} - -/** * Return a list of all config entity types provided by a module. * * @param string $module diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 63b601b..72c68f0 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Datetime; use Drupal\Component\Utility\Xss; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\LanguageConfigContext; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityManager; @@ -40,6 +41,13 @@ class Date { */ protected $languageManager; + /** + * Config factory for handling language contexts for date formats. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + protected $country = NULL; protected $dateFormats = array(); @@ -51,9 +59,10 @@ class Date { * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. */ - public function __construct(EntityManager $entity_manager, LanguageManager $language_manager) { + public function __construct(EntityManager $entity_manager, LanguageManager $language_manager, ConfigFactory $config_factory) { $this->dateFormatStorage = $entity_manager->getStorageController('date_format'); $this->languageManager = $language_manager; + $this->configFactory = $config_factory; } /** @@ -144,12 +153,13 @@ protected function dateFormat($format, $langcode = NULL) { $needs_language_context = !empty($langcode); if (!$needs_language_context) { // If we are at any context we try to get the language from there. - $context = config_context(); + $context = $this->configFactory->getContext(); if ($context !== NULL && $contextLanguage = $context->get(LanguageConfigContext::LANGUAGE_KEY)) { $langcode = $contextLanguage; } else { $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; + $needs_language_context = TRUE; } } if (!isset($this->dateFormats[$format][$langcode])) {