Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -13,6 +13,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
|
|||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageDefault;
|
||||
use Drupal\Core\Language\LanguageManager;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\Config\LanguageConfigFactoryOverrideInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
@ -469,7 +470,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
unset($predefined[$key]);
|
||||
continue;
|
||||
}
|
||||
$predefined[$key] = $this->t($value[0]);
|
||||
$predefined[$key] = new TranslatableMarkup($value[0]);
|
||||
}
|
||||
asort($predefined);
|
||||
return $predefined;
|
||||
|
|
|
@ -47,7 +47,7 @@ class LanguageConfiguration extends FormElement {
|
|||
'#type' => 'select',
|
||||
'#title' => t('Default language'),
|
||||
'#options' => $options + static::getDefaultOptions(),
|
||||
'#description' => t('Explanation of the language options is found on the <a href="@languages_list_page">languages list page</a>.', array('@languages_list_page' => \Drupal::url('entity.configurable_language.collection'))),
|
||||
'#description' => t('Explanation of the language options is found on the <a href=":languages_list_page">languages list page</a>.', array(':languages_list_page' => \Drupal::url('entity.configurable_language.collection'))),
|
||||
'#default_value' => ($default_config != NULL) ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT,
|
||||
);
|
||||
|
||||
|
@ -96,7 +96,7 @@ class LanguageConfiguration extends FormElement {
|
|||
*/
|
||||
protected static function getDefaultOptions() {
|
||||
$language_options = array(
|
||||
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->getName())),
|
||||
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (@language)", array('@language' => static::languageManager()->getDefaultLanguage()->getName())),
|
||||
'current_interface' => t('Interface text language selected for page'),
|
||||
'authors_default' => t("Author's preferred language"),
|
||||
);
|
||||
|
|
|
@ -200,7 +200,7 @@ class ContentLanguageSettings extends ConfigEntityBase implements ContentLanguag
|
|||
$bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
|
||||
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
|
||||
|
||||
return $this->dependencies;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
$form['predefined_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add language'),
|
||||
'#name' => 'add_language',
|
||||
'#limit_validation_errors' => array(array('predefined_langcode'), array('predefined_submit')),
|
||||
'#states' => array(
|
||||
'invisible' => array(
|
||||
|
@ -76,6 +77,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
$form['custom_language']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add custom language'),
|
||||
'#name' => 'add_custom_language',
|
||||
'#validate' => array('::validateCustom'),
|
||||
'#submit' => array('::submitForm', '::save'),
|
||||
);
|
||||
|
@ -96,7 +98,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
if ($this->moduleHandler->moduleExists('block')) {
|
||||
// Tell the user they have the option to add a language switcher block
|
||||
// to their theme so they can switch between the languages.
|
||||
drupal_set_message($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href="@block-admin">block administration page</a>.', array('@block-admin' => $this->url('block.admin_display'))));
|
||||
drupal_set_message($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href=":block-admin">block administration page</a>.', array(':block-admin' => $this->url('block.admin_display'))));
|
||||
}
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
'#required' => TRUE,
|
||||
'#default_value' => '',
|
||||
'#disabled' => FALSE,
|
||||
'#description' => $this->t('Use language codes as <a href="@w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')),
|
||||
'#description' => $this->t('Use language codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array(':w3ctags' => 'http://www.w3.org/International/articles/language-tags/')),
|
||||
);
|
||||
}
|
||||
$form['label'] = array(
|
||||
|
@ -101,9 +101,9 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
public function validateCommon(array $form, FormStateInterface $form_state) {
|
||||
// Ensure sane field values for langcode and name.
|
||||
if (!isset($form['langcode_view']) && !preg_match('@^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$@', $form_state->getValue('langcode'))) {
|
||||
$form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href="@url">defined by the W3C</a>.', array(
|
||||
$form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', array(
|
||||
'%field' => $form['langcode']['#title'],
|
||||
'@url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
':url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
}
|
||||
if ($form_state->getValue('label') != Html::escape($form_state->getValue('label'))) {
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\language\Form;
|
|||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\ConfigurableLanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -82,15 +83,21 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
}
|
||||
else {
|
||||
$language_options = array(
|
||||
$this->t('Existing languages') => $existing_languages,
|
||||
$this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
|
||||
(string) $this->t('Existing languages') => $existing_languages,
|
||||
(string) $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
|
||||
);
|
||||
}
|
||||
|
||||
$form['mappings'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#theme' => 'language_negotiation_configure_browser_form_table',
|
||||
);
|
||||
$form['mappings'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => [
|
||||
$this->t('Browser language code'),
|
||||
$this->t('Site language'),
|
||||
$this->t('Operations'),
|
||||
],
|
||||
'#attributes' => ['id' => 'language-negotiation-browser'],
|
||||
'#empty' => $this->t('No browser language mappings available.'),
|
||||
];
|
||||
|
||||
$mappings = $this->language_get_browser_drupal_langcode_mappings();
|
||||
foreach ($mappings as $browser_langcode => $drupal_langcode) {
|
||||
|
@ -112,6 +119,15 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
'#required' => TRUE,
|
||||
),
|
||||
);
|
||||
// Operations column.
|
||||
$form['mappings'][$browser_langcode]['operations'] = [
|
||||
'#type' => 'operations',
|
||||
'#links' => [],
|
||||
];
|
||||
$form['mappings'][$browser_langcode]['operations']['#links']['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $browser_langcode]),
|
||||
];
|
||||
}
|
||||
|
||||
// Add empty row.
|
||||
|
@ -123,7 +139,7 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
$form['new_mapping']['browser_langcode'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Browser language code'),
|
||||
'#description' => $this->t('Use language codes as <a href="@w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')),
|
||||
'#description' => $this->t('Use language codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array(':w3ctags' => 'http://www.w3.org/International/articles/language-tags/')),
|
||||
'#size' => 20,
|
||||
);
|
||||
$form['new_mapping']['drupal_langcode'] = array(
|
||||
|
|
|
@ -153,8 +153,8 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
if (!($default_langcode == $langcode) && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
|
||||
// Throw a form error if the prefix is blank for a non-default language,
|
||||
// although it is required for selected negotiation type.
|
||||
$form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may only be left blank for the <a href="@url">selected detection fallback language.</a>', [
|
||||
'@url' => $this->getUrlGenerator()->generate('language.negotiation_selected'),
|
||||
$form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may only be left blank for the <a href=":url">selected detection fallback language.</a>', [
|
||||
':url' => $this->getUrlGenerator()->generate('language.negotiation_selected'),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,16 +125,31 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
|
|||
protected function initProcessors($scope) {
|
||||
$interface = '\Drupal\Core\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
|
||||
$this->processors[$scope] = array();
|
||||
$weights = [];
|
||||
foreach ($this->languageManager->getLanguageTypes() as $type) {
|
||||
foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
|
||||
if (!isset($this->processors[$scope][$method_id])) {
|
||||
$reflector = new \ReflectionClass($method['class']);
|
||||
if ($reflector->implementsInterface($interface)) {
|
||||
$this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
|
||||
$weights[$method_id] = $method['weight'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the processors list, so that their functions are called in the
|
||||
// order specified by the weight of the methods.
|
||||
uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use($weights) {
|
||||
$a_weight = $weights[$method_id_a];
|
||||
$b_weight = $weights[$method_id_b];
|
||||
|
||||
if ($a_weight == $b_weight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a_weight < $b_weight) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,18 +22,18 @@ class LanguageAccessControlHandler extends EntityAccessControlHandler {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
switch ($operation) {
|
||||
case 'update':
|
||||
/* @var \Drupal\Core\Language\LanguageInterface $entity */
|
||||
return AccessResult::allowedIf(!$entity->isLocked())->cacheUntilEntityChanges($entity)
|
||||
->andIf(parent::checkAccess($entity, $operation, $langcode, $account));
|
||||
->andIf(parent::checkAccess($entity, $operation, $account));
|
||||
|
||||
case 'delete':
|
||||
/* @var \Drupal\Core\Language\LanguageInterface $entity */
|
||||
return AccessResult::allowedIf(!$entity->isLocked())->cacheUntilEntityChanges($entity)
|
||||
->andIf(AccessResult::allowedIf(!$entity->isDefault())->cacheUntilEntityChanges($entity))
|
||||
->andIf(parent::checkAccess($entity, $operation, $langcode, $account));
|
||||
->andIf(parent::checkAccess($entity, $operation, $account));
|
||||
|
||||
default:
|
||||
// No opinion.
|
||||
|
|
|
@ -56,7 +56,7 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a new EntityListController object.
|
||||
* Constructs a new LanguageListBuilder object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
|
|
|
@ -26,7 +26,7 @@ class LanguageBlock extends DeriverBase {
|
|||
$configurable_types = $language_manager->getLanguageTypes();
|
||||
foreach ($configurable_types as $type) {
|
||||
$this->derivatives[$type] = $base_plugin_definition;
|
||||
$this->derivatives[$type]['admin_label'] = t('Language switcher (!type)', array('!type' => $info[$type]['name']));
|
||||
$this->derivatives[$type]['admin_label'] = t('Language switcher (@type)', array('@type' => $info[$type]['name']));
|
||||
}
|
||||
// If there is just one configurable type then change the title of the
|
||||
// block.
|
||||
|
|
|
@ -144,7 +144,10 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
|
|||
foreach ($this->languageManager->getNativeLanguages() as $language) {
|
||||
$langcode = $language->getId();
|
||||
$links[$langcode] = array(
|
||||
'url' => $url,
|
||||
// We need to clone the $url object to avoid using the same one for all links.
|
||||
// When the links are rendered, options are set on the $url object,
|
||||
// so if we use the same one, they would be set for all links.
|
||||
'url' => clone $url,
|
||||
'title' => $language->getName(),
|
||||
'attributes' => array('class' => array('language-link')),
|
||||
'query' => $query,
|
||||
|
|
|
@ -200,7 +200,10 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
|
||||
foreach ($this->languageManager->getNativeLanguages() as $language) {
|
||||
$links[$language->getId()] = array(
|
||||
'url' => $url,
|
||||
// We need to clone the $url object to avoid using the same one for all links.
|
||||
// When the links are rendered, options are set on the $url object,
|
||||
// so if we use the same one, they would be set for all links.
|
||||
'url' => clone $url,
|
||||
'title' => $language->getName(),
|
||||
'language' => $language,
|
||||
'attributes' => array('class' => array('language-link')),
|
||||
|
|
38
core/modules/language/src/Tests/ConfigurableLanguageTest.php
Normal file
38
core/modules/language/src/Tests/ConfigurableLanguageTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\language\Tests\ConfigurableLanguageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
|
||||
/**
|
||||
* Tests configurable language name methods.
|
||||
*/
|
||||
public function testName() {
|
||||
$name = $this->randomMachineName();
|
||||
$language_code = $this->randomMachineName(2);
|
||||
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
|
||||
$this->assertEqual($configurableLanguage->getName(), $name);
|
||||
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
|
||||
}
|
||||
|
||||
}
|
|
@ -29,9 +29,9 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
|
|||
*/
|
||||
public function testConfigOverrideImport() {
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
/* @var \Drupal\Core\Config\StorageInterface $staging */
|
||||
$staging = \Drupal::service('config.storage.staging');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $staging);
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
// Uninstall the language module and its dependencies so we can test
|
||||
// enabling the language module and creating overrides at the same time
|
||||
|
@ -41,11 +41,11 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
|
|||
// ConfigFactory.
|
||||
$this->rebuildContainer();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_staging */
|
||||
$override_staging = $staging->createCollection('language.fr');
|
||||
// Create some overrides in staging.
|
||||
$override_staging->write('system.site', array('name' => 'FR default site name'));
|
||||
$override_staging->write('system.maintenance', array('message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience'));
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', array('name' => 'FR default site name'));
|
||||
$override_sync->write('system.maintenance', array('message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience'));
|
||||
|
||||
$this->configImporter()->import();
|
||||
$this->rebuildContainer();
|
||||
|
@ -71,14 +71,14 @@ class LanguageConfigOverrideImportTest extends WebTestBase {
|
|||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $staging */
|
||||
$staging = \Drupal::service('config.storage.staging');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $staging);
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_staging */
|
||||
$override_staging = $staging->createCollection('language.fr');
|
||||
// Create some overrides in staging.
|
||||
$override_staging->write('system.site', array('name' => 'FR default site name'));
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', array('name' => 'FR default site name'));
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
|
||||
$this->configImporter()->import();
|
||||
|
|
|
@ -152,7 +152,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that the configuration is updated when the node type is changed.
|
||||
* Tests that the configuration is retained when the node type is updated.
|
||||
*/
|
||||
public function testNodeTypeUpdate() {
|
||||
// Create the article content type first if the profile used is not the
|
||||
|
@ -172,16 +172,16 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$uuid = $configuration->uuid();
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Article content type.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Article content type.');
|
||||
// Rename the article content type.
|
||||
// Update the article content type by changing the title label.
|
||||
$edit = array(
|
||||
'type' => 'article_2'
|
||||
'title_label' => 'Name'
|
||||
);
|
||||
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
|
||||
// Check that we still have the settings for the new node type.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article_2');
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Article content type.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Article content type.');
|
||||
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.');
|
||||
// Check that we still have the settings for the updated node type.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the updated Article content type.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the updated Article content type.');
|
||||
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the updated Article content type.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,7 +220,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that the configuration is updated when a vocabulary is changed.
|
||||
* Tests that the configuration is retained when a vocabulary is updated.
|
||||
*/
|
||||
public function testTaxonomyVocabularyUpdate() {
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
|
@ -242,16 +242,16 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$uuid = $configuration->uuid();
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Country vocabulary.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Country vocabulary.');
|
||||
// Rename the vocabulary.
|
||||
// Update the vocabulary.
|
||||
$edit = array(
|
||||
'vid' => 'nation'
|
||||
'name' => 'Nation'
|
||||
);
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save'));
|
||||
// Check that we still have the settings for the new vocabulary.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'nation');
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Country vocabulary.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Country vocabulary.');
|
||||
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Country vocabulary.');
|
||||
// Check that we still have the settings for the updated vocabulary.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country');
|
||||
$this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the updated Country vocabulary.');
|
||||
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the updated Country vocabulary.');
|
||||
$this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the updated Country vocabulary.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
|
|||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
// Test validation on missing values.
|
||||
$this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
|
||||
$this->assertText(t('!name field is required.', array('!name' => t('Language name'))));
|
||||
$this->assertText(t('@name field is required.', array('@name' => t('Language code'))));
|
||||
$this->assertText(t('@name field is required.', array('@name' => t('Language name'))));
|
||||
$empty_language = new Language();
|
||||
$this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
|
||||
$this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
|
@ -55,9 +55,9 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
|
|||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
$this->assertRaw(t('%field must be a valid language tag as <a href="@url">defined by the W3C</a>.', array(
|
||||
$this->assertRaw(t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', array(
|
||||
'%field' => t('Language code'),
|
||||
'@url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
':url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
|
||||
$this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name'))));
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\language\Tests;
|
|||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
@ -24,7 +25,7 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'language', 'block', 'language_test');
|
||||
public static $modules = array('locale', 'locale_test', 'language', 'block', 'language_test', 'menu_ui');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -205,20 +206,20 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
/** @var \Drupal\Core\Routing\UrlGenerator $generator */
|
||||
$generator = $this->container->get('url_generator');
|
||||
|
||||
// Verfify the English URL is correct
|
||||
// Verify the English URL is correct
|
||||
list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
|
||||
':id' => 'block-test-language-block',
|
||||
':hreflang' => 'en',
|
||||
));
|
||||
$english_url = $generator->generateFromPath('user/2', array('language' => $languages['en']));
|
||||
$english_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['en']));
|
||||
$this->assertEqual($english_url, (string) $english_link['href']);
|
||||
|
||||
// Verfify the Italian URL is correct
|
||||
// Verify the Italian URL is correct
|
||||
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
|
||||
':id' => 'block-test-language-block',
|
||||
':hreflang' => 'it',
|
||||
));
|
||||
$italian_url = $generator->generateFromPath('user/2', array('language' => $languages['it']));
|
||||
$italian_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['it']));
|
||||
$this->assertEqual($italian_url, (string) $italian_link['href']);
|
||||
}
|
||||
|
||||
|
@ -292,7 +293,7 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$function_name = '#type link';
|
||||
$path = 'language_test/type-link-active-class';
|
||||
|
||||
// Test links generated by _l() on an English page.
|
||||
// Test links generated by the link generator on an English page.
|
||||
$current_language = 'English';
|
||||
$this->drupalGet($path);
|
||||
|
||||
|
@ -317,7 +318,7 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$this->assertIdentical($settings['path']['isFront'], FALSE, 'drupalSettings.path.isFront is set correctly to allow drupal.active-link to mark the correct links as active.');
|
||||
$this->assertIdentical($settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as active.');
|
||||
|
||||
// Test links generated by _l() on a French page.
|
||||
// Test links generated by the link generator on a French page.
|
||||
$current_language = 'French';
|
||||
$this->drupalGet('fr/language_test/type-link-active-class');
|
||||
|
||||
|
@ -353,7 +354,7 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
$this->drupalLogout();
|
||||
|
||||
// Test links generated by _l() on an English page.
|
||||
// Test links generated by the link generator on an English page.
|
||||
$current_language = 'English';
|
||||
$this->drupalGet('language_test/type-link-active-class');
|
||||
|
||||
|
@ -372,7 +373,7 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', array(':id' => 'fr_link', ':class' => 'is-active'));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
|
||||
// Test links generated by _l() on a French page.
|
||||
// Test links generated by the link generator on a French page.
|
||||
$current_language = 'French';
|
||||
$this->drupalGet('fr/language_test/type-link-active-class');
|
||||
|
||||
|
@ -392,6 +393,58 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test language switcher links for session based negotiation.
|
||||
*/
|
||||
function testLanguageSessionSwitchLinks() {
|
||||
// Add language.
|
||||
$edit = array(
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Enable session language detection and selection.
|
||||
$edit = array(
|
||||
'language_interface[enabled][language-url]' => FALSE,
|
||||
'language_interface[enabled][language-session]' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Enable the language switching block.
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array(
|
||||
'id' => 'test_language_block',
|
||||
));
|
||||
|
||||
// Enable the main menu block.
|
||||
$this->drupalPlaceBlock('system_menu_block:main', array(
|
||||
'id' => 'test_menu',
|
||||
));
|
||||
|
||||
// Add a link to the homepage.
|
||||
$link = MenuLinkContent::create([
|
||||
'title' => 'Home',
|
||||
'menu_name' => 'main',
|
||||
'bundle' => 'menu_link_content',
|
||||
'link' => [['uri' => 'entity:user/2']],
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
// Go to the homepage.
|
||||
$this->drupalGet('');
|
||||
// Click on the French link.
|
||||
$this->clickLink(t('French'));
|
||||
// There should be a query parameter to set the session language.
|
||||
$this->assertUrl('user/2', ['query' => ['language' => 'fr']]);
|
||||
// Click on the 'Home' Link.
|
||||
$this->clickLink(t('Home'));
|
||||
// There should be no query parameter.
|
||||
$this->assertUrl('user/2');
|
||||
// Click on the French link.
|
||||
$this->clickLink(t('French'));
|
||||
// There should be no query parameter.
|
||||
$this->assertUrl('user/2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the native name of a language entity in configuration as a label.
|
||||
*
|
||||
|
|
|
@ -393,6 +393,9 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
// it is set by JavaScript.
|
||||
$this->drupalLogout();
|
||||
|
||||
// Place a site branding block in the header region.
|
||||
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
|
||||
|
||||
// Access the front page without specifying any valid URL language prefix
|
||||
// and having as browser language preference a non-default language.
|
||||
$http_header = array("Accept-Language: $langcode_browser_fallback;q=1");
|
||||
|
@ -406,7 +409,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
|
||||
|
||||
// Check that URLs are rewritten using the given browser language.
|
||||
$fields = $this->xpath('//strong[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
|
||||
$fields = $this->xpath('//div[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
|
||||
$this->assertTrue($fields[0] == 'Drupal', 'URLs are rewritten using the browser language.');
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue