Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -0,0 +1,81 @@
<?php
/**
* @file
* Contains \Drupal\Core\Language\ContextProvider\CurrentLanguageContext.
*/
namespace Drupal\Core\Language\ContextProvider;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Sets the current language as a context.
*/
class CurrentLanguageContext implements ContextProviderInterface {
use StringTranslationTrait;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new CurrentLanguageContext.
*
* @param \Drupal\Core\Language\LanguageManagerInterface
* The language manager.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
// Add a context for each language type.
$language_types = $this->languageManager->getLanguageTypes();
$info = $this->languageManager->getDefinedLanguageTypesInfo();
if ($unqualified_context_ids) {
foreach ($unqualified_context_ids as $unqualified_context_id) {
if (array_search($unqualified_context_id, $language_types) === FALSE) {
unset($language_types[$unqualified_context_id]);
}
}
}
$result = [];
foreach ($language_types as $type_key) {
if (isset($info[$type_key]['name'])) {
$context = new Context(new ContextDefinition('language', $info[$type_key]['name']));
$context->setContextValue($this->languageManager->getCurrentLanguage($type_key));
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['languages:' . $type_key]);
$context->addCacheableDependency($cacheability);
$result[$type_key] = $context;
}
}
return $result;
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return $this->getRuntimeContexts([]);
}
}

View file

@ -87,28 +87,43 @@ class LanguageManager implements LanguageManagerInterface {
}
/**
* {@inheritdoc}
* Returns information about all defined language types.
*
* Defines the three core language types:
* - Interface language is the only configurable language type in core. It is
* used by t() as the default language if none is specified.
* - Content language is by default non-configurable and inherits the
* interface language negotiated value. It is used by the Field API to
* determine the display language for fields if no explicit value is
* specified.
* - URL language is by default non-configurable and is determined through the
* URL language negotiation method or the URL fallback language negotiation
* method if no language can be detected. It is used by l() as the default
* language if none is specified.
*
* @return array
* An associative array of language type information arrays keyed by
* language type machine name, in the format of
* hook_language_types_info().
*/
public function getDefinedLanguageTypesInfo() {
// This needs to have the same return value as
// language_language_type_info(), so that even if the Language module is
// not defined, users of this information, such as the Views module, can
// access names and descriptions of the default language types.
return array(
$this->definedLanguageTypesInfo = array(
LanguageInterface::TYPE_INTERFACE => array(
'name' => $this->t('Interface text'),
'description' => $this->t('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'),
'name' => new TranslationWrapper('Interface text'),
'description' => new TranslationWrapper('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'),
'locked' => TRUE,
),
LanguageInterface::TYPE_CONTENT => array(
'name' => $this->t('Content'),
'description' => $this->t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
'name' => new TranslationWrapper('Content'),
'description' => new TranslationWrapper('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
'locked' => TRUE,
),
LanguageInterface::TYPE_URL => array(
'locked' => TRUE,
),
);
return $this->definedLanguageTypesInfo;
}
/**