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

@ -282,42 +282,6 @@ function language_get_default_langcode($entity_type, $bundle) {
return $configuration->getDefaultLangcode();
}
/**
* Implements hook_language_types_info().
*
* 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.
*/
function language_language_types_info() {
return array(
LanguageInterface::TYPE_INTERFACE => array(
'name' => t('Interface text'),
'description' => 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.'),
'locked' => TRUE,
),
LanguageInterface::TYPE_CONTENT => array(
'name' => t('Content'),
'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
'fixed' => array(LanguageNegotiationUI::METHOD_ID),
'locked' => TRUE,
),
LanguageInterface::TYPE_URL => array(
'name' => t('URL'),
'description' => t('Order of language detection methods for URLs. The detected language will be used as the default when generating URLs for internal links on the site.'),
'fixed' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID),
'locked' => TRUE,
),
);
}
/**
* Reads language prefixes and uses the langcode if no prefix is set.
*/
@ -540,3 +504,16 @@ function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
}
}
}
/**
* Implements hook_language_types_info_alter().
*
* We can't set the fixed properties in \Drupal\Core\Language\LanguageManager,
* where the rest of the properties for the default language types are defined.
* The LanguageNegation classes are only loaded when the language module is
* enabled and we can't be sure of that in the LanguageManager.
*/
function language_language_types_info_alter(array &$language_types) {
$language_types[LanguageInterface::TYPE_CONTENT]['fixed'] = [LanguageNegotiationUI::METHOD_ID];
$language_types[LanguageInterface::TYPE_URL]['fixed'] = [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID];
}

View file

@ -9,7 +9,7 @@ services:
- [initLanguageManager]
language.config_subscriber:
class: Drupal\language\EventSubscriber\ConfigSubscriber
arguments: ['@language_manager', '@language.default']
arguments: ['@language_manager', '@language.default', '@config.factory']
tags:
- { name: event_subscriber }
language.config_factory_override:

View file

@ -7,8 +7,6 @@
namespace Drupal\language\Config;
use Drupal\Component\Utility\SafeMarkup;
/**
* Provides a common trait for working with language override collection names.
*/
@ -45,7 +43,7 @@ trait LanguageConfigCollectionNameTrait {
protected function getLangcodeFromCollectionName($collection) {
preg_match('/^language\.(.*)$/', $collection, $matches);
if (!isset($matches[1])) {
throw new \InvalidArgumentException(SafeMarkup::format('!collection is not a valid language override collection', array('!collection' => $collection)));
throw new \InvalidArgumentException("'$collection' is not a valid language override collection");
}
return $matches[1];
}

View file

@ -7,6 +7,7 @@
namespace Drupal\language\Config;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigCollectionInfo;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigFactoryOverrideBase;
@ -222,4 +223,15 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements
}
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
if ($this->language) {
$metadata->setCacheContexts(['languages:language_interface']);
}
return $metadata;
}
}

View file

@ -8,7 +8,6 @@
namespace Drupal\language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PhpStorage\PhpStorageFactory;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\Language;
@ -105,7 +104,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
* {@inheritdoc}
*/
public static function rebuildServices() {
PhpStorageFactory::get('service_container')->deleteAll();
\Drupal::service('kernel')->invalidateContainer();
}
/**
@ -183,10 +182,14 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
*/
public function getDefinedLanguageTypesInfo() {
if (!isset($this->languageTypesInfo)) {
$defaults = parent::getDefinedLanguageTypesInfo();
$info = $this->moduleHandler->invokeAll('language_types_info');
$language_info = $info + $defaults;
// Let other modules alter the list of language types.
$this->moduleHandler->alter('language_types_info', $info);
$this->languageTypesInfo = $info;
$this->moduleHandler->alter('language_types_info', $language_info);
$this->languageTypesInfo = $language_info;
}
return $this->languageTypesInfo;
}

View file

@ -7,7 +7,6 @@
namespace Drupal\language\Entity;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\LanguageInterface;
@ -200,7 +199,7 @@ class ContentLanguageSettings extends ConfigEntityBase implements ContentLanguag
// If the target entity type uses entities to manage its bundles then
// depend on the bundle entity.
if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->target_bundle)) {
throw new \LogicException(SafeMarkup::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->target_bundle)));
throw new \LogicException("Missing bundle entity, entity type $bundle_entity_type_id, entity id {$this->target_bundle}.");
}
$this->addDependency('config', $bundle_entity->getConfigDependencyName());
}

View file

@ -7,11 +7,13 @@
namespace Drupal\language\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageDefault;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\PhpStorage\PhpStorageFactory;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents;
use Drupal\language\ConfigurableLanguageManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@ -33,6 +35,13 @@ class ConfigSubscriber implements EventSubscriberInterface {
*/
protected $languageDefault;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a new class object.
*
@ -40,31 +49,58 @@ class ConfigSubscriber implements EventSubscriberInterface {
* The language manager.
* @param \Drupal\Core\Language\LanguageDefault $language_default
* The default language.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(LanguageManagerInterface $language_manager, LanguageDefault $language_default) {
public function __construct(LanguageManagerInterface $language_manager, LanguageDefault $language_default, ConfigFactoryInterface $config_factory) {
$this->languageManager = $language_manager;
$this->languageDefault = $language_default;
$this->configFactory = $config_factory;
}
/**
* Causes the container to be rebuilt on the next request.
*
* This event subscriber assumes that the new default langcode and old default
* langcode are valid langcodes. If the schema definition of either
* system.site:default_langcode or language.negotiation::url.prefixes changes
* then this event must be changed to work with both the old and new schema
* definition so this event is update safe.
*
* @param ConfigCrudEvent $event
* The configuration event.
*/
public function onConfigSave(ConfigCrudEvent $event) {
$saved_config = $event->getConfig();
if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) {
$language = $this->languageManager->getLanguage($saved_config->get('default_langcode'));
$new_default_langcode = $saved_config->get('default_langcode');
$default_language = $this->configFactory->get('language.entity.' . $new_default_langcode);
// During an import the language might not exist yet.
if ($language) {
$this->languageDefault->set($language);
if (!$default_language->isNew()) {
$this->languageDefault->set(new Language($default_language->get()));
$this->languageManager->reset();
language_negotiation_url_prefixes_update();
// Directly update language negotiation settings instead of calling
// language_negotiation_url_prefixes_update() to ensure that the code
// obeys the hook_update_N() restrictions.
$negotiation_config = $this->configFactory->getEditable('language.negotiation');
$negotiation_changed = FALSE;
$url_prefixes = $negotiation_config->get('url.prefixes');
$old_default_langcode = $saved_config->getOriginal('default_langcode');
if (empty($url_prefixes[$old_default_langcode])) {
$negotiation_config->set('url.prefixes.' . $old_default_langcode, $old_default_langcode);
$negotiation_changed = TRUE;
}
if (empty($url_prefixes[$new_default_langcode])) {
$negotiation_config->set('url.prefixes.' . $new_default_langcode, '');
$negotiation_changed = TRUE;
}
if ($negotiation_changed) {
$negotiation_config->save(TRUE);
}
}
// Trigger a container rebuild on the next request by deleting compiled
// from PHP storage.
PhpStorageFactory::get('service_container')->deleteAll();
// Trigger a container rebuild on the next request by invalidating it.
ConfigurableLanguageManager::rebuildServices();
}
}

View file

@ -301,7 +301,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
$table_form['enabled'][$method_id]['#attributes'] = array('disabled' => 'disabled');
}
$table_form['description'][$method_id] = array('#markup' => Xss::filterAdmin($method['description']));
$table_form['description'][$method_id] = array('#markup' => $method['description']);
$config_op = array();
if (isset($method['config_route_name'])) {

View file

@ -8,10 +8,10 @@
namespace Drupal\language\HttpKernel;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\LanguageNegotiatorInterface;
use Symfony\Component\HttpFoundation\Request;
@ -95,7 +95,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL) {
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
if (!isset($this->multilingual)) {
$this->multilingual = $this->languageManager->isMultilingual();
}
@ -106,7 +106,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
$this->initProcessors($scope);
}
foreach ($this->processors[$scope] as $instance) {
$path = $instance->processOutbound($path, $options, $request, $cacheable_metadata);
$path = $instance->processOutbound($path, $options, $request, $bubbleable_metadata);
}
// No language dependent path allowed in this mode.
if (empty($this->processors[$scope])) {

View file

@ -7,9 +7,9 @@
namespace Drupal\language\Plugin\LanguageNegotiation;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Url;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\language\LanguageSwitcherInterface;
@ -86,7 +86,7 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL) {
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
if ($request) {
// The following values are not supposed to change during a single page
// request processing.
@ -115,10 +115,10 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
if (!isset($options['query'][$this->queryParam])) {
$options['query'][$this->queryParam] = $this->queryValue;
}
if ($cacheable_metadata) {
if ($bubbleable_metadata) {
// Cached URLs that have been processed by this outbound path
// processor must be:
$cacheable_metadata
$bubbleable_metadata
// - invalidated when the language negotiation config changes, since
// another query parameter may be used to determine the language.
->addCacheTags($this->config->get('language.negotiation')->getCacheTags())

View file

@ -7,10 +7,10 @@
namespace Drupal\language\Plugin\LanguageNegotiation;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Url;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\language\LanguageSwitcherInterface;
@ -123,7 +123,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
/**
* Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processOutbound().
*/
public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL) {
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
$url_scheme = 'http';
$port = 80;
if ($request) {
@ -144,8 +144,8 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->getId()])) {
$options['prefix'] = $config['prefixes'][$options['language']->getId()] . '/';
if ($cacheable_metadata) {
$cacheable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
}
}
}
@ -184,8 +184,8 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
// Add Drupal's subfolder from the base_path if there is one.
$options['base_url'] .= rtrim(base_path(), '/');
if ($cacheable_metadata) {
$cacheable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
}
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
* @file
* Contains Drupal\language\ProxyClass\LanguageConverter.
*/
/**
* This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\language\LanguageConverter' "core/modules/language/src".
*/
namespace Drupal\language\ProxyClass {
/**
* Provides a proxy class for \Drupal\language\LanguageConverter.
*
* @see \Drupal\Component\ProxyBuilder
*/
class LanguageConverter implements \Drupal\Core\ParamConverter\ParamConverterInterface
{
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
/**
* The id of the original proxied service.
*
* @var string
*/
protected $drupalProxyOriginalServiceId;
/**
* The real proxied service, after it was lazy loaded.
*
* @var \Drupal\language\LanguageConverter
*/
protected $service;
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Constructs a ProxyClass Drupal proxy object.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container.
* @param string $drupal_proxy_original_service_id
* The service ID of the original service.
*/
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id)
{
$this->container = $container;
$this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
}
/**
* Lazy loads the real service from the container.
*
* @return object
* Returns the constructed real service.
*/
protected function lazyLoadItself()
{
if (!isset($this->service)) {
$this->service = $this->container->get($this->drupalProxyOriginalServiceId);
}
return $this->service;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults)
{
return $this->lazyLoadItself()->convert($value, $definition, $name, $defaults);
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, \Symfony\Component\Routing\Route $route)
{
return $this->lazyLoadItself()->applies($definition, $name, $route);
}
}
}

View file

@ -34,7 +34,7 @@ class LanguageListModuleInstallTest extends WebTestBase {
$this->drupalLogin($admin_user);
$edit = array();
$edit['modules[Multilingual][language][enable]'] = 'language';
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->assertEqual(\Drupal::state()->get('language_test.language_count_preinstall', 0), 1, 'Using LanguageManager::getLanguages() returns 1 language during Language installation.');

View file

@ -139,7 +139,7 @@ class LanguageUrlRewritingTest extends WebTestBase {
// Create an absolute French link.
$language = \Drupal::languageManager()->getLanguage('fr');
$url = Url::fromRoute('<none>', [], [
$url = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
'language' => $language,
])->toString();
@ -149,7 +149,7 @@ class LanguageUrlRewritingTest extends WebTestBase {
$this->assertEqual($url, $expected, 'The right port is used.');
// If we set the port explicitly, it should not be overridden.
$url = Url::fromRoute('<none>', [], [
$url = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
'language' => $language,
'base_url' => $request->getBaseUrl() . ':90',

View file

@ -8,8 +8,8 @@
namespace Drupal\Tests\language\Unit {
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Session\UserSession;
use Drupal\Tests\UnitTestCase;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
@ -91,10 +91,10 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
$method->setCurrentUser($this->user);
$this->assertEquals($expected_langcode, $method->getLangcode($request));
$cacheability = new CacheableMetadata();
$cacheability = new BubbleableMetadata();
$options = [];
$method->processOutbound('foo', $options, $request, $cacheability);
$expected_cacheability = new CacheableMetadata();
$expected_cacheability = new BubbleableMetadata();
if ($expected_langcode) {
$this->assertSame($prefix . '/', $options['prefix']);
$expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
@ -180,10 +180,10 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
$method->setCurrentUser($this->user);
$this->assertEquals($expected_langcode, $method->getLangcode($request));
$cacheability = new CacheableMetadata();
$cacheability = new BubbleableMetadata();
$options = [];
$this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
$expected_cacheability = new CacheableMetadata();
$expected_cacheability = new BubbleableMetadata();
if ($expected_langcode !== FALSE && count($domains) > 1) {
$expected_cacheability->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
}