Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -5,7 +5,6 @@
|
|||
* Administration functions for language.module.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -170,7 +169,7 @@ function template_preprocess_language_content_settings_table(&$variables) {
|
|||
'data' => array(
|
||||
'#prefix' => '<label>',
|
||||
'#suffix' => '</label>',
|
||||
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
|
||||
'#plain_text' => $element[$bundle]['settings']['#label'],
|
||||
),
|
||||
'class' => array('bundle'),
|
||||
),
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
* Makes language negotiation inherit user interface negotiation.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attach behavior to language negotiation admin user interface.
|
||||
*/
|
||||
Drupal.behaviors.negotiationLanguage = {
|
||||
attach: function () {
|
||||
|
|
|
@ -284,6 +284,9 @@ function language_get_default_langcode($entity_type, $bundle) {
|
|||
|
||||
/**
|
||||
* Reads language prefixes and uses the langcode if no prefix is set.
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal::config('language.negotiation')->get('url.prefixes') instead.
|
||||
*/
|
||||
function language_negotiation_url_prefixes() {
|
||||
return \Drupal::config('language.negotiation')->get('url.prefixes');
|
||||
|
@ -293,7 +296,8 @@ function language_negotiation_url_prefixes() {
|
|||
* Update the list of prefixes from the installed languages.
|
||||
*/
|
||||
function language_negotiation_url_prefixes_update() {
|
||||
$prefixes = language_negotiation_url_prefixes();
|
||||
$config = \Drupal::configFactory()->getEditable('language.negotiation');
|
||||
$prefixes = $config->get('url.prefixes');
|
||||
foreach (\Drupal::languageManager()->getLanguages() as $language) {
|
||||
// The prefix for this language should be updated if it's not assigned yet
|
||||
// or the prefix is set to the empty string.
|
||||
|
@ -304,38 +308,19 @@ function language_negotiation_url_prefixes_update() {
|
|||
}
|
||||
// Otherwise we keep the configured prefix.
|
||||
}
|
||||
language_negotiation_url_prefixes_save($prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves language prefix settings.
|
||||
*/
|
||||
function language_negotiation_url_prefixes_save(array $prefixes) {
|
||||
// @todo https://www.drupal.org/node/2403229 $prefixes can contain
|
||||
// configuration overrides.
|
||||
\Drupal::configFactory()->getEditable('language.negotiation')
|
||||
->set('url.prefixes', $prefixes)
|
||||
->save();
|
||||
$config->set('url.prefixes', $prefixes)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads language domains.
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal::config('language.negotiation')->get('url.domains') instead.
|
||||
*/
|
||||
function language_negotiation_url_domains() {
|
||||
return \Drupal::config('language.negotiation')->get('url.domains');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the language domain settings.
|
||||
*/
|
||||
function language_negotiation_url_domains_save(array $domains) {
|
||||
// @todo https://www.drupal.org/node/2403229 $domains can contain
|
||||
// configuration overrides.
|
||||
\Drupal::configFactory()->getEditable('language.negotiation')
|
||||
->set('url.domains', $domains)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_modules_installed().
|
||||
*/
|
||||
|
@ -376,9 +361,10 @@ function language_configurable_language_insert(ConfigurableLanguageInterface $la
|
|||
}
|
||||
|
||||
// Add language to the list of language domains.
|
||||
$domains = language_negotiation_url_domains();
|
||||
$config = \Drupal::configFactory()->getEditable('language.negotiation');
|
||||
$domains = $config->get('url.domains');
|
||||
$domains[$language->id()] = '';
|
||||
language_negotiation_url_domains_save($domains);
|
||||
$config->set('url.domains', $domains)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -386,14 +372,16 @@ function language_configurable_language_insert(ConfigurableLanguageInterface $la
|
|||
*/
|
||||
function language_configurable_language_delete(ConfigurableLanguageInterface $language) {
|
||||
// Remove language from language prefix list.
|
||||
$prefixes = language_negotiation_url_prefixes();
|
||||
$config = \Drupal::configFactory()->getEditable('language.negotiation');
|
||||
$prefixes = $config->get('url.prefixes');
|
||||
unset($prefixes[$language->id()]);
|
||||
language_negotiation_url_prefixes_save($prefixes);
|
||||
$config->set('url.prefixes', $prefixes)->save();
|
||||
|
||||
// Remove language from language domain list.
|
||||
$domains = language_negotiation_url_domains();
|
||||
$config = \Drupal::configFactory()->getEditable('language.negotiation');
|
||||
$domains = $config->get('url.domains');
|
||||
unset($domains[$language->id()]);
|
||||
language_negotiation_url_domains_save($domains);
|
||||
$config->set('url.domains', $domains)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -427,12 +415,12 @@ function language_form_alter(&$form, FormStateInterface $form_state) {
|
|||
// Content entity forms may have added a langcode field. But content language
|
||||
// configuration should decide if it should be exposed or not in the forms.
|
||||
$form_object = $form_state->getFormObject();
|
||||
if ($form_object instanceof ContentEntityFormInterface) {
|
||||
if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()->getEntityType()->hasKey('langcode')) {
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $form_object->getEntity();
|
||||
$entity_type = $entity->getEntityType();
|
||||
$langcode_key = $entity_type->getKey('langcode');
|
||||
if (isset($form[$langcode_key]) && $entity_type->isTranslatable()) {
|
||||
if (isset($form[$langcode_key])) {
|
||||
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
|
||||
$form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
id: d7_language_negotiation_settings
|
||||
label: Drupal 7 language negotiation settings
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- locale_language_negotiation_session_param
|
||||
- locale_language_negotiation_url_part
|
||||
process:
|
||||
'session/parameter': locale_language_negotiation_session_param
|
||||
'url/source': locale_language_negotiation_url_part
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.negotiation
|
|
@ -194,15 +194,12 @@ class ContentLanguageSettings extends ConfigEntityBase implements ContentLanguag
|
|||
*/
|
||||
public function calculateDependencies() {
|
||||
parent::calculateDependencies();
|
||||
$bundle_entity_type_id = $this->entityManager()->getDefinition($this->target_entity_type_id)->getBundleEntityType();
|
||||
if ($bundle_entity_type_id != 'bundle') {
|
||||
// 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("Missing bundle entity, entity type $bundle_entity_type_id, entity id {$this->target_bundle}.");
|
||||
}
|
||||
$this->addDependency('config', $bundle_entity->getConfigDependencyName());
|
||||
}
|
||||
|
||||
// Create dependency on the bundle.
|
||||
$entity_type = \Drupal::entityManager()->getDefinition($this->target_entity_type_id);
|
||||
$bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
|
||||
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
|
||||
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\language\Form;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
@ -106,7 +106,7 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
'@url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
}
|
||||
if ($form_state->getValue('label') != SafeMarkup::checkPlain($form_state->getValue('label'))) {
|
||||
if ($form_state->getValue('label') != Html::escape($form_state->getValue('label'))) {
|
||||
$form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', array('%field' => $form['label']['#title'])));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\language\Form;
|
||||
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
|
@ -277,22 +276,22 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
|
||||
if (isset($types[$type])) {
|
||||
$table_form['#language_negotiation_info'][$method_id] = $method;
|
||||
$method_name = SafeMarkup::checkPlain($method['name']);
|
||||
$method_name = $method['name'];
|
||||
|
||||
$table_form['weight'][$method_id] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => $this->t('Weight for !title language detection method', array('!title' => Unicode::strtolower($method_name))),
|
||||
'#title' => $this->t('Weight for @title language detection method', array('@title' => Unicode::strtolower($method_name))),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $weight,
|
||||
'#attributes' => array('class' => array("language-method-weight-$type")),
|
||||
'#delta' => 20,
|
||||
);
|
||||
|
||||
$table_form['title'][$method_id] = array('#markup' => $method_name);
|
||||
$table_form['title'][$method_id] = array('#plain_text' => $method_name);
|
||||
|
||||
$table_form['enabled'][$method_id] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Enable !title language detection method', array('!title' => Unicode::strtolower($method_name))),
|
||||
'#title' => $this->t('Enable @title language detection method', array('@title' => Unicode::strtolower($method_name))),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $enabled,
|
||||
);
|
||||
|
|
|
@ -111,8 +111,8 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
);
|
||||
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
$prefixes = language_negotiation_url_prefixes();
|
||||
$domains = language_negotiation_url_domains();
|
||||
$prefixes = $config->get('url.prefixes');
|
||||
$domains = $config->get('url.domains');
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$t_args = array('%language' => $language->getName(), '%langcode' => $language->getId());
|
||||
$form['prefix'][$langcode] = array(
|
||||
|
@ -211,12 +211,11 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
// Save selected format (prefix or domain).
|
||||
$this->config('language.negotiation')
|
||||
->set('url.source', $form_state->getValue('language_negotiation_url_part'))
|
||||
// Save new domain and prefix values.
|
||||
->set('url.prefixes', $form_state->getValue('prefix'))
|
||||
->set('url.domains', $form_state->getValue('domain'))
|
||||
->save();
|
||||
|
||||
// Save new domain and prefix values.
|
||||
language_negotiation_url_prefixes_save($form_state->getValue('prefix'));
|
||||
language_negotiation_url_domains_save($form_state->getValue('domain'));
|
||||
|
||||
parent::submitForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $this->getLabel($entity);
|
||||
$row['label'] = $entity->label();
|
||||
$row['default'] = array(
|
||||
'#type' => 'radio',
|
||||
'#parents' => array('site_default_language'),
|
||||
|
|
|
@ -66,7 +66,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
* particular logic to return a language code. For instance, the URL method
|
||||
* searches for a valid path prefix or domain name in the current request URL.
|
||||
* If a language negotiation method does not return a valid language code, the
|
||||
* next method associated to the language type (based on method weight) is
|
||||
* next method associated with the language type (based on method weight) is
|
||||
* invoked.
|
||||
*
|
||||
* Modules can define additional language negotiation methods by simply provide
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language\Tests\EntityTypeWithoutLanguageFormTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests entity type without language support.
|
||||
*
|
||||
* This is to ensure that an entity type without language support can not
|
||||
* enable the language select from the content language settings page.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class EntityTypeWithoutLanguageFormTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'language',
|
||||
'language_test',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and login administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
'administer languages',
|
||||
));
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests configuration options with an entity without language definition.
|
||||
*/
|
||||
public function testEmptyLangcode() {
|
||||
// Assert that we can not enable language select from
|
||||
// content language settings page.
|
||||
$this->drupalGet('admin/config/regional/content-language');
|
||||
$this->assertNoField('entity_types[no_language_entity_test]');
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ class LanguagePathMonolingualTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'path');
|
||||
public static $modules = ['block', 'language', 'path'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -56,6 +56,7 @@ class LanguagePathMonolingualTest extends WebTestBase {
|
|||
// Set language detection to URL.
|
||||
$edit = array('language_interface[enabled][language-url]' => TRUE);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ class LanguageTourTest extends TourTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'tour');
|
||||
public static $modules = ['block', 'language', 'tour'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -37,6 +37,7 @@ class LanguageTourTest extends TourTestBase {
|
|||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'access tour'));
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language\Tests\Migrate\d7\MigrateLanguageNegotiationSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language negotiation variables.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_language_negotiation_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of language negotiation variables to language.negotiation.yml.
|
||||
*/
|
||||
public function testLanguageNegotiation() {
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertIdentical($config->get('session.parameter'), 'language');
|
||||
$this->assertIdentical($config->get('url.source'), 'domain');
|
||||
}
|
||||
|
||||
}
|
|
@ -8,12 +8,12 @@
|
|||
namespace Drupal\language\Tests\Views;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\views\Tests\ViewUnitTestBase;
|
||||
use Drupal\views\Tests\ViewKernelTestBase;
|
||||
|
||||
/**
|
||||
* Defines the base class for all Language handler tests.
|
||||
*/
|
||||
abstract class LanguageTestBase extends ViewUnitTestBase {
|
||||
abstract class LanguageTestBase extends ViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language_test\Entity\NoLanguageEntityTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "no_language_entity_test",
|
||||
* label = @Translation("Test entity without language support"),
|
||||
* base_table = "no_language_entity_test",
|
||||
* persistent_cache = FALSE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class NoLanguageEntityTest extends ContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields['id'] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('ID'))
|
||||
->setDescription(t('The ID of the test entity.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
|
||||
$fields['uuid'] = BaseFieldDefinition::create('uuid')
|
||||
->setLabel(t('UUID'))
|
||||
->setDescription(t('The UUID of the test entity.'))
|
||||
->setReadOnly(TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -88,26 +88,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
*/
|
||||
public function testCalculateDependencies() {
|
||||
// Mock the interfaces necessary to create a dependency on a bundle entity.
|
||||
$bundle_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$bundle_entity->expects($this->any())
|
||||
->method('getConfigDependencyName')
|
||||
->will($this->returnValue('test.test_entity_type.id'));
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
|
||||
$storage->expects($this->any())
|
||||
->method('load')
|
||||
->with('test_bundle')
|
||||
->will($this->returnValue($bundle_entity));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('bundle_entity_type')
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleEntityType')
|
||||
->will($this->returnValue('bundle_entity_type'));
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(array('type' => 'config', 'name' => 'test.test_entity_type.id')));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
|
|
Reference in a new issue