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
|
@ -1,7 +1,8 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: en
|
||||
label: English
|
||||
direction: 'ltr'
|
||||
direction: ltr
|
||||
weight: 0
|
||||
locked: false
|
||||
status: true
|
||||
langcode: en
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: und
|
||||
label: 'Not specified'
|
||||
direction: 'ltr'
|
||||
weight: 1
|
||||
direction: ltr
|
||||
weight: 2
|
||||
locked: true
|
||||
status: true
|
||||
langcode: en
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: zxx
|
||||
label: 'Not applicable'
|
||||
direction: 'ltr'
|
||||
weight: 2
|
||||
direction: ltr
|
||||
weight: 3
|
||||
locked: true
|
||||
status: true
|
||||
langcode: en
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
id: language-add
|
||||
module: language
|
||||
label: 'Adding languages'
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: language-add
|
||||
label: 'Adding languages'
|
||||
module: language
|
||||
routes:
|
||||
- route_name: language.add
|
||||
tips:
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
id: language-edit
|
||||
module: language
|
||||
label: Editing languages
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: language-edit
|
||||
label: 'Editing languages'
|
||||
module: language
|
||||
routes:
|
||||
- route_name: entity.configurable_language.edit_form
|
||||
tips:
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
id: language
|
||||
module: language
|
||||
label: Language
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: language
|
||||
label: Language
|
||||
module: language
|
||||
routes:
|
||||
- route_name: entity.configurable_language.collection
|
||||
tips:
|
||||
|
@ -34,7 +36,7 @@ tips:
|
|||
body: '<p>You can change the default language of the site by choosing one of your configured languages as default. The site will use the default language in situations where no choice is made but a language should be set, for example as the language of the displayed interface.</p>'
|
||||
weight: 4
|
||||
attributes:
|
||||
data-class: form-item-site-default-language
|
||||
data-class: js-form-item-site-default-language
|
||||
language-operations:
|
||||
id: language-operations
|
||||
plugin: text
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Prepares variables for language negotiation configuration form.
|
||||
|
@ -94,55 +93,6 @@ function template_preprocess_language_negotiation_configure_form(&$variables) {
|
|||
$variables['children'] = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme browser configuration form as table.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - form: A render element representing the form.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_language_negotiation_configure_browser_form_table($variables) {
|
||||
$form = $variables['form'];
|
||||
$rows = array();
|
||||
foreach (Element::children($form, TRUE) as $key) {
|
||||
$row = array();
|
||||
$row[] = drupal_render($form[$key]['browser_langcode']);
|
||||
$row[] = drupal_render($form[$key]['drupal_langcode']);
|
||||
$links = array();
|
||||
$links['delete'] = array(
|
||||
'title' => t('Delete'),
|
||||
'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $key]),
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => array(
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
),
|
||||
);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$header = array(
|
||||
t('Browser language code'),
|
||||
t('Site language'),
|
||||
t('Operations'),
|
||||
);
|
||||
|
||||
$table = array(
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('No browser language mappings available.'),
|
||||
'#attributes' => array('id' => 'language-negotiation-browser'),
|
||||
);
|
||||
$output = drupal_render($table);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
|
||||
*/
|
||||
|
@ -201,5 +151,5 @@ function template_preprocess_language_content_settings_table(&$variables) {
|
|||
* @ingroup themeable
|
||||
*/
|
||||
function theme_language_content_settings_table($variables) {
|
||||
return '<h4>' . $variables['build']['#title'] . '</h4>' . drupal_render($variables['build']);
|
||||
return '<h4>' . theme_render_and_autoescape($variables['build']['#title']) . '</h4>' . theme_render_and_autoescape($variables['build']);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
entity.configurable_language.collection:
|
||||
title: Languages
|
||||
description: 'Configure languages for content and the user interface.'
|
||||
description: 'Configure languages for content, interface, and configuration.'
|
||||
route_name: entity.configurable_language.collection
|
||||
parent: system.admin_config_regional
|
||||
language.content_settings_page:
|
||||
|
|
|
@ -29,42 +29,42 @@ function language_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.language':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Language module allows you to configure the languages used on your site, and provides information for the for <a href="!content">Content Translation</a>, <a href="!interface">Interface Translation</a>, and <a href="!configuration">Configuration Translation</a> modules, if they are enabled. For more information, see <a href="!doc_url">the online documentation for the Language module</a>.', array('!doc_url' => 'https://www.drupal.org/documentation/modules/language', '!content' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#', '!interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', array('name' => 'locale')) : '#', '!configuration' => (\Drupal::moduleHandler()->moduleExists('config_translation')) ? \Drupal::url('help.page', array('name' => 'config_translation')) : '#')) . '</p>';
|
||||
$output .= '<p>' . t('The Language module allows you to configure the languages used on your site, and provides information for the for <a href=":content">Content Translation</a>, <a href=":interface">Interface Translation</a>, and <a href=":configuration">Configuration Translation</a> modules, if they are enabled. For more information, see the <a href=":doc_url">online documentation for the Language module</a>.', array(':doc_url' => 'https://www.drupal.org/documentation/modules/language', ':content' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#', ':interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', array('name' => 'locale')) : '#', ':configuration' => (\Drupal::moduleHandler()->moduleExists('config_translation')) ? \Drupal::url('help.page', array('name' => 'config_translation')) : '#')) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Adding languages') . '</dt>';
|
||||
$output .= '<dd>' . t('You can add languages on the <a href="!language_list">Languages</a> page by selecting <em>Add language</em> and choosing a language from the drop-down menu. This language is then displayed in the languages list, where it can be configured further. If the <a href="!interface">Interface translation module</a> is enabled, and the <em>translation server</em> is set as a translation source, then the interface translation for this language is automatically downloaded as well.' , array('!language_list' => \Drupal::url('entity.configurable_language.collection'), '!interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', array('name' => 'locale')) : '#')) . '</dd>';
|
||||
$output .= '<dd>' . t('You can add languages on the <a href=":language_list">Languages</a> page by selecting <em>Add language</em> and choosing a language from the drop-down menu. This language is then displayed in the languages list, where it can be configured further. If the <a href=":interface">Interface translation module</a> is enabled, and the <em>translation server</em> is set as a translation source, then the interface translation for this language is automatically downloaded as well.' , array(':language_list' => \Drupal::url('entity.configurable_language.collection'), ':interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', array('name' => 'locale')) : '#')) . '</dd>';
|
||||
$output .= '<dt>' . t('Adding custom languages') . '</dt>';
|
||||
$output .= '<dd>' . t('You can add a language that is not provided in the drop-down list by choosing <em>Custom language</em> at the end of the list. You then have to configure its language code, name, and direction in the form provided.') . '</dd>';
|
||||
$output .= '<dt>' . t('Configuring content languages') . '</dt>';
|
||||
$output .= '<dd>' . t('By default, content is created in the site\'s default language and no language selector is displayed on content creation pages. On the <a href="!content_language">Content language</a> page you can customize the language configuration for any supported content entity on your site (for example for content types or menu links). After choosing an entity, you are provided with a drop-down menu to set the default language and a check-box to display language selectors.', array('!content_language' => \Drupal::url('language.content_settings_page'))) . '</dd>';
|
||||
$output .= '<dd>' . t('By default, content is created in the site\'s default language and no language selector is displayed on content creation pages. On the <a href=":content_language">Content language</a> page you can customize the language configuration for any supported content entity on your site (for example for content types or menu links). After choosing an entity, you are provided with a drop-down menu to set the default language and a check-box to display language selectors.', array(':content_language' => \Drupal::url('language.content_settings_page'))) . '</dd>';
|
||||
$output .= '<dt>' . t('Adding a language switcher block') . '</dt>';
|
||||
$output .= '<dd>' . t('If the Block module is enabled, then you can add a language switcher block on the <a href="!blocks">Block layout</a> page to allow users to switch between languages.', array('!blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
|
||||
$output .= '<dd>' . t('If the Block module is enabled, then you can add a language switcher block on the <a href=":blocks">Block layout</a> page to allow users to switch between languages.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
|
||||
$output .= '<dt>' . t('Making a block visible per language') . '</dt>';
|
||||
$output .= '<dd>' . t('If the Block module is enabled, then the Language module allows you to set the visibility of a block based on selected languages on the <a href="!blocks">Block layout</a> page.', array('!blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
|
||||
$output .= '<dd>' . t('If the Block module is enabled, then the Language module allows you to set the visibility of a block based on selected languages on the <a href=":blocks">Block layout</a> page.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
|
||||
$output .= '<dt>' . t('Choosing user languages') . '</dt>';
|
||||
$output .= '<dd>' . t('Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user\'s language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user\'s profile page if the <em>Account administration pages</em> method is enabled (see below).') . '</dd>';
|
||||
$output .= '<dt>' . t('Language detection and selection') . '</dt>';
|
||||
$output .= '<dd>' . t('The <a href="!detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', array('!detection' => \Drupal::url('language.negotiation')));
|
||||
$output .= '<dd>' . t('The <a href=":detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', array(':detection' => \Drupal::url('language.negotiation')));
|
||||
$output .= '<ul><li>' . t('<em>URL</em> sets the interface language based on a path prefix or domain (for example specifying <em>de</em> for German would result in URLs like <em>example.com/de/contact</em>). The default language does not require a path prefix, but can have one assigned as well. If the language detection is done by domain name, a domain needs to be specified for each language.') . '</li>';
|
||||
$output .= '<li>' . t('<em>Session</em> determines the interface language from a request or session parameter (for example <em>example.com?language=de</em> would set the interface language to German based on the use of <em>de</em> as the <em>language</em> parameter).') . '</li>';
|
||||
$output .= '<li>' . t('<em>User</em> follows the language configuration set on the user\'s profile page.') . '</li>';
|
||||
$output .= '<li>' . t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href="!language_list">language codes</a> used on your site.', array('!language_list' => \Drupal::url('entity.configurable_language.collection'))) . '</li>';
|
||||
$output .= '<li>' . t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href=":language_list">language codes</a> used on your site.', array(':language_list' => \Drupal::url('entity.configurable_language.collection'))) . '</li>';
|
||||
$output .= '<li>' . t('<em>Account administration pages</em> follows the configuration set as <em>Administration pages language</em> on the profile page of an administrative user. This method is similar to the <em>User</em> method, but only sets the interface text language on administration pages, independent of the interface text language on other pages.') . '</li>';
|
||||
$output .= '<li>' . t('<em>Selected language</em> allows you to specify the site\'s default language or a specific language as the fall-back language. This method should be listed last.') . '</li></ul></dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
case 'entity.configurable_language.collection':
|
||||
$output = '<p>' . t('Reorder the configured languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact <a href="@detection">detection and selection</a>.', array('@detection' => \Drupal::url('language.negotiation'))) . '</p>';
|
||||
$output .= '<p>' . t('The site default language can also be set. It is not recommended to change the default language on a working site. <a href="@language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', array('@language-detection' => \Drupal::url('language.negotiation'))) . '</p>';
|
||||
$output = '<p>' . t('Reorder the configured languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact <a href=":detection">detection and selection</a>.', array(':detection' => \Drupal::url('language.negotiation'))) . '</p>';
|
||||
$output .= '<p>' . t('The site default language can also be set. It is not recommended to change the default language on a working site. <a href=":language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', array(':language-detection' => \Drupal::url('language.negotiation'))) . '</p>';
|
||||
return $output;
|
||||
|
||||
case 'language.add':
|
||||
return '<p>' . t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>';
|
||||
|
||||
case 'language.negotiation':
|
||||
$output = '<p>' . t('Define how to decide which language is used to display page elements (primarily text provided by modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Be aware that some language detection methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the <a href="!admin-change-language">list of languages</a>.', array('!admin-change-language' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
$output = '<p>' . t('Define how to decide which language is used to display page elements (primarily text provided by modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Be aware that some language detection methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the <a href=":admin-change-language">list of languages</a>.', array(':admin-change-language' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
return $output;
|
||||
|
||||
case 'language.negotiation_session':
|
||||
|
@ -72,11 +72,11 @@ function language_help($route_name, RouteMatchInterface $route_match) {
|
|||
return $output;
|
||||
|
||||
case 'language.negotiation_browser':
|
||||
$output = '<p>' . t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to <a href="!configure-languages">site languages</a>.', array('!configure-languages' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
$output = '<p>' . t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to <a href=":configure-languages">site languages</a>.', array(':configure-languages' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
return $output;
|
||||
|
||||
case 'language.negotiation_selected':
|
||||
$output = '<p>' . t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (e.g., when using an empty path prefix or using the default domain). <a href="!admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.', array('!admin-change-language' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
$output = '<p>' . t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (e.g., when using an empty path prefix or using the default domain). <a href=":admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.', array(':admin-change-language' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
return $output;
|
||||
|
||||
case 'entity.block.edit_form':
|
||||
|
@ -105,11 +105,6 @@ function language_theme() {
|
|||
'render element' => 'form',
|
||||
'file' => 'language.admin.inc',
|
||||
),
|
||||
'language_negotiation_configure_browser_form_table' => array(
|
||||
'render element' => 'form',
|
||||
'file' => 'language.admin.inc',
|
||||
'function' => 'theme_language_negotiation_configure_browser_form_table',
|
||||
),
|
||||
'language_content_settings_table' => array(
|
||||
'render element' => 'element',
|
||||
'file' => 'language.admin.inc',
|
||||
|
@ -217,15 +212,6 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_rename().
|
||||
*/
|
||||
function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) {
|
||||
ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle_old)
|
||||
->setTargetBundle($bundle_new)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_delete().
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_language_negotiation_settings
|
||||
label: Drupal 7 language negotiation settings
|
||||
label: Language negotiation settings
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -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')),
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\ConfigurableLanguageTest.
|
||||
* Contains \Drupal\language\Tests\ConfigurableLanguageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language;
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
|
@ -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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
{% for language_type in language_types %}
|
||||
{%
|
||||
set language_classes = [
|
||||
'js-form-item',
|
||||
'form-item',
|
||||
'table-language-group',
|
||||
'table-' ~ language_type.type ~ '-wrapper',
|
||||
|
|
|
@ -71,7 +71,8 @@ class LanguageTestController implements ContainerInjectionInterface {
|
|||
/**
|
||||
* Returns links to the current page with different langcodes.
|
||||
*
|
||||
* Using #type 'link' causes these links to be rendered with _l().
|
||||
* Using #type 'link' causes these links to be rendered with the link
|
||||
* generator.
|
||||
*/
|
||||
public function typeLinkActiveClass() {
|
||||
// We assume that 'en' and 'fr' have been configured.
|
||||
|
|
|
@ -102,7 +102,7 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$dependencies = $config->calculateDependencies();
|
||||
$dependencies = $config->calculateDependencies()->getDependencies();
|
||||
$this->assertContains('test.test_entity_type.id', $dependencies['config']);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_contexts_manager', $cache_contexts_manager);
|
||||
\Drupal::setContainer($container);
|
||||
|
|
Reference in a new issue