Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -68,11 +68,16 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements
|
|||
* An event dispatcher instance to use for configuration events.
|
||||
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
|
||||
* The typed configuration manager.
|
||||
* @param \Drupal\Core\Language\LanguageDefault $default_language
|
||||
* The default language.
|
||||
*/
|
||||
public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) {
|
||||
public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config, LanguageDefault $default_language) {
|
||||
$this->baseStorage = $storage;
|
||||
$this->eventDispatcher = $event_dispatcher;
|
||||
$this->typedConfigManager = $typed_config;
|
||||
// Prior to negiotiation the override language should be the default
|
||||
// language.
|
||||
$this->language = $default_language->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +88,7 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements
|
|||
$storage = $this->getStorage($this->language->getId());
|
||||
return $storage->readMultiple($names);
|
||||
}
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,10 @@ interface LanguageConfigFactoryOverrideInterface extends ConfigFactoryOverrideIn
|
|||
* The default language.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This
|
||||
* method has been replaced by injecting the default language into the
|
||||
* constructor.
|
||||
*/
|
||||
public function setLanguageFromDefault(LanguageDefault $language_default = NULL);
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class LanguageConfigOverride extends StorableConfigBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete() {
|
||||
$this->data = array();
|
||||
$this->data = [];
|
||||
$this->storage->delete($this->name);
|
||||
Cache::invalidateTags($this->getCacheTags());
|
||||
$this->isNew = TRUE;
|
||||
|
|
|
@ -168,7 +168,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
*/
|
||||
protected function loadLanguageTypesConfiguration() {
|
||||
if (!$this->languageTypes) {
|
||||
$this->languageTypes = $this->configFactory->get('language.types')->get() ?: array('configurable' => array(), 'all' => parent::getLanguageTypes());
|
||||
$this->languageTypes = $this->configFactory->get('language.types')->get() ?: ['configurable' => [], 'all' => parent::getLanguageTypes()];
|
||||
}
|
||||
return $this->languageTypes;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
// afterwards. This can happen for instance while parsing negotiation
|
||||
// method definitions.
|
||||
elseif ($type == LanguageInterface::TYPE_INTERFACE) {
|
||||
return new Language(array('id' => LanguageInterface::LANGCODE_SYSTEM));
|
||||
return new Language(['id' => LanguageInterface::LANGCODE_SYSTEM]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,11 +241,11 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
public function reset($type = NULL) {
|
||||
if (!isset($type)) {
|
||||
$this->initialized = FALSE;
|
||||
$this->negotiatedLanguages = array();
|
||||
$this->negotiatedMethods = array();
|
||||
$this->negotiatedLanguages = [];
|
||||
$this->negotiatedMethods = [];
|
||||
$this->languageTypes = NULL;
|
||||
$this->languageTypesInfo = NULL;
|
||||
$this->languages = array();
|
||||
$this->languages = [];
|
||||
if ($this->negotiator) {
|
||||
$this->negotiator->reset();
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
public function setNegotiator(LanguageNegotiatorInterface $negotiator) {
|
||||
$this->negotiator = $negotiator;
|
||||
$this->initialized = FALSE;
|
||||
$this->negotiatedLanguages = array();
|
||||
$this->negotiatedLanguages = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,7 +292,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
// and the configuration entities for languages are not yet fully
|
||||
// imported.
|
||||
$default = $this->getDefaultLanguage();
|
||||
$languages = array($default->getId() => $default);
|
||||
$languages = [$default->getId() => $default];
|
||||
$languages += $this->getDefaultLockedLanguages($default->getWeight());
|
||||
|
||||
// Load configurable languages on top of the defaults. Ideally this could
|
||||
|
@ -325,7 +325,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
*/
|
||||
public function getNativeLanguages() {
|
||||
$languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
|
||||
$natives = array();
|
||||
$natives = [];
|
||||
|
||||
$original_language = $this->getConfigOverrideLanguage();
|
||||
|
||||
|
@ -363,9 +363,9 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFallbackCandidates(array $context = array()) {
|
||||
public function getFallbackCandidates(array $context = []) {
|
||||
if ($this->isMultilingual()) {
|
||||
$candidates = array();
|
||||
$candidates = [];
|
||||
if (empty($context['operation']) || $context['operation'] != 'locale_lookup') {
|
||||
// If the fallback context is not locale_lookup, initialize the
|
||||
// candidates with languages ordered by weight and add
|
||||
|
@ -379,13 +379,13 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
// The first candidate should always be the desired language if
|
||||
// specified.
|
||||
if (!empty($context['langcode'])) {
|
||||
$candidates = array($context['langcode'] => $context['langcode']) + $candidates;
|
||||
$candidates = [$context['langcode'] => $context['langcode']] + $candidates;
|
||||
}
|
||||
}
|
||||
|
||||
// Let other modules hook in and add/change candidates.
|
||||
$type = 'language_fallback_candidates';
|
||||
$types = array();
|
||||
$types = [];
|
||||
if (!empty($context['operation'])) {
|
||||
$types[] = $type . '_' . $context['operation'];
|
||||
}
|
||||
|
@ -414,8 +414,8 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
|
|||
|
||||
if (!empty($result)) {
|
||||
// Allow modules to provide translations for specific links.
|
||||
$this->moduleHandler->alter('language_switch_links', $result, $type, $path);
|
||||
$links = (object) array('links' => $result, 'method_id' => $method_id);
|
||||
$this->moduleHandler->alter('language_switch_links', $result, $type, $url);
|
||||
$links = (object) ['links' => $result, 'method_id' => $method_id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ interface ConfigurableLanguageManagerInterface extends LanguageManagerInterface
|
|||
* @param string $langcode
|
||||
* The language code for the override.
|
||||
*
|
||||
* @return \Drupal\Core\Config\StorageInterface $storage
|
||||
* @return \Drupal\Core\Config\StorageInterface
|
||||
* A storage object to use for reading and writing the
|
||||
* configuration override.
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ class DefaultLanguageItem extends LanguageItem {
|
|||
$langcode = $this->getDefaultLangcode($entity);
|
||||
}
|
||||
// Always notify otherwise default langcode will not be set correctly.
|
||||
$this->setValue(array('value' => $langcode), TRUE);
|
||||
$this->setValue(['value' => $langcode], TRUE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use Drupal\Core\Language\LanguageInterface;
|
|||
use Drupal\Core\Render\Element\FormElement;
|
||||
|
||||
/**
|
||||
* Provides language element configuration.
|
||||
* Defines an element for language configuration for a single field.
|
||||
*
|
||||
* @FormElement("language_configuration")
|
||||
*/
|
||||
|
@ -18,50 +18,50 @@ class LanguageConfiguration extends FormElement {
|
|||
*/
|
||||
public function getInfo() {
|
||||
$class = get_class($this);
|
||||
return array(
|
||||
return [
|
||||
'#input' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
'#process' => array(
|
||||
array($class, 'processLanguageConfiguration'),
|
||||
),
|
||||
);
|
||||
'#process' => [
|
||||
[$class, 'processLanguageConfiguration'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process handler for the language_configuration form element.
|
||||
*/
|
||||
public static function processLanguageConfiguration(&$element, FormStateInterface $form_state, &$form) {
|
||||
$options = isset($element['#options']) ? $element['#options'] : array();
|
||||
$options = isset($element['#options']) ? $element['#options'] : [];
|
||||
// Avoid validation failure since we are moving the '#options' key in the
|
||||
// nested 'language' select element.
|
||||
unset($element['#options']);
|
||||
/** @var \Drupal\language\Entity\ContentLanguageSettings $default_config */
|
||||
$default_config = $element['#default_value'];
|
||||
$element['langcode'] = array(
|
||||
$element['langcode'] = [
|
||||
'#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>.', [':languages_list_page' => \Drupal::url('entity.configurable_language.collection')]),
|
||||
'#default_value' => ($default_config != NULL) ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT,
|
||||
);
|
||||
];
|
||||
|
||||
$element['language_alterable'] = array(
|
||||
$element['language_alterable'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show language selector on create and edit pages'),
|
||||
'#default_value' => ($default_config != NULL) ? $default_config->isLanguageAlterable() : FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
// Add the entity type and bundle information to the form if they are set.
|
||||
// They will be used, in the submit handler, to generate the names of the
|
||||
// configuration entities that will store the settings and are a way to uniquely
|
||||
// identify the entity.
|
||||
$language = $form_state->get('language') ?: [];
|
||||
$language += array(
|
||||
$element['#name'] => array(
|
||||
$language += [
|
||||
$element['#name'] => [
|
||||
'entity_type' => $element['#entity_information']['entity_type'],
|
||||
'bundle' => $element['#entity_information']['bundle'],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$form_state->set('language', $language);
|
||||
|
||||
// Do not add the submit callback for the language content settings page,
|
||||
|
@ -89,15 +89,15 @@ class LanguageConfiguration extends FormElement {
|
|||
* An array containing the default options.
|
||||
*/
|
||||
protected static function getDefaultOptions() {
|
||||
$language_options = array(
|
||||
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (@language)", array('@language' => static::languageManager()->getDefaultLanguage()->getName())),
|
||||
$language_options = [
|
||||
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (@language)", ['@language' => static::languageManager()->getDefaultLanguage()->getName()]),
|
||||
'current_interface' => t('Interface text language selected for page'),
|
||||
'authors_default' => t("Author's preferred language"),
|
||||
);
|
||||
];
|
||||
|
||||
$languages = static::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();
|
||||
$language_options[$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
|
||||
}
|
||||
|
||||
return $language_options;
|
||||
|
|
|
@ -246,18 +246,18 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
|
|||
if (!isset($standard_languages[$langcode])) {
|
||||
// Drupal does not know about this language, so we set its values with the
|
||||
// best guess. The user will be able to edit afterwards.
|
||||
return static::create(array(
|
||||
return static::create([
|
||||
'id' => $langcode,
|
||||
'label' => $langcode,
|
||||
));
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// A known predefined language, details will be filled in properly.
|
||||
return static::create(array(
|
||||
return static::create([
|
||||
'id' => $langcode,
|
||||
'label' => $standard_languages[$langcode][0],
|
||||
'direction' => isset($standard_languages[$langcode][2]) ? $standard_languages[$langcode][2] : static::DIRECTION_LTR,
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,8 +140,8 @@ class ConfigSubscriber implements EventSubscriberInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = array('onConfigSave', 0);
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave', 0];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,16 +64,14 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the request on the language manager.
|
||||
* Sets the default language and initializes configuration overrides.
|
||||
*
|
||||
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
|
||||
* The Event to process.
|
||||
*/
|
||||
public function onKernelRequestLanguage(GetResponseEvent $event) {
|
||||
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
|
||||
$request = $event->getRequest();
|
||||
$this->negotiator->setCurrentUser($this->currentUser);
|
||||
$this->negotiator->reset();
|
||||
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
|
||||
$this->languageManager->setNegotiator($this->negotiator);
|
||||
$this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage());
|
||||
|
@ -91,8 +89,8 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
|
|||
* @return array
|
||||
* An array of event listener definitions.
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[KernelEvents::REQUEST][] = array('onKernelRequestLanguage', 255);
|
||||
public static function getSubscribedEvents() {
|
||||
$events[KernelEvents::REQUEST][] = ['onKernelRequestLanguage', 255];
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
|
|
@ -52,11 +52,11 @@ class ContentLanguageSettingsForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$entity_types = $this->entityManager->getDefinitions();
|
||||
$labels = array();
|
||||
$default = array();
|
||||
$labels = [];
|
||||
$default = [];
|
||||
|
||||
$bundles = $this->entityManager->getAllBundleInfo();
|
||||
$language_configuration = array();
|
||||
$language_configuration = [];
|
||||
foreach ($entity_types as $entity_type_id => $entity_type) {
|
||||
if (!$entity_type instanceof ContentEntityTypeInterface || !$entity_type->hasKey('langcode') || !isset($bundles[$entity_type_id])) {
|
||||
continue;
|
||||
|
@ -76,65 +76,65 @@ class ContentLanguageSettingsForm extends FormBase {
|
|||
|
||||
asort($labels);
|
||||
|
||||
$form = array(
|
||||
$form = [
|
||||
'#labels' => $labels,
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'language/drupal.language.admin',
|
||||
),
|
||||
),
|
||||
'#attributes' => array(
|
||||
],
|
||||
],
|
||||
'#attributes' => [
|
||||
'class' => 'language-content-settings-form',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$form['entity_types'] = array(
|
||||
$form['entity_types'] = [
|
||||
'#title' => $this->t('Custom language settings'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $labels,
|
||||
'#default_value' => $default,
|
||||
);
|
||||
];
|
||||
|
||||
$form['settings'] = array('#tree' => TRUE);
|
||||
$form['settings'] = ['#tree' => TRUE];
|
||||
|
||||
foreach ($labels as $entity_type_id => $label) {
|
||||
$entity_type = $entity_types[$entity_type_id];
|
||||
|
||||
$form['settings'][$entity_type_id] = array(
|
||||
$form['settings'][$entity_type_id] = [
|
||||
'#title' => $label,
|
||||
'#type' => 'container',
|
||||
'#entity_type' => $entity_type_id,
|
||||
'#theme' => 'language_content_settings_table',
|
||||
'#bundle_label' => $entity_type->getBundleLabel() ?: $label,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="entity_types[' . $entity_type_id . ']"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="entity_types[' . $entity_type_id . ']"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) {
|
||||
$form['settings'][$entity_type_id][$bundle]['settings'] = array(
|
||||
$form['settings'][$entity_type_id][$bundle]['settings'] = [
|
||||
'#type' => 'item',
|
||||
'#label' => $bundle_info['label'],
|
||||
'language' => array(
|
||||
'language' => [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => array(
|
||||
'#entity_information' => [
|
||||
'entity_type' => $entity_type_id,
|
||||
'bundle' => $bundle,
|
||||
),
|
||||
],
|
||||
'#default_value' => $language_configuration[$entity_type_id][$bundle],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$form['actions']['#type'] = 'actions';
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save configuration'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -143,9 +143,13 @@ class ContentLanguageSettingsForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$entity_types = $form_state->getValue('entity_types');
|
||||
foreach ($form_state->getValue('settings') as $entity_type => $entity_settings) {
|
||||
foreach ($entity_settings as $bundle => $bundle_settings) {
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle);
|
||||
if (empty($entity_types[$entity_type])) {
|
||||
$bundle_settings['settings']['language']['language_alterable'] = FALSE;
|
||||
}
|
||||
$config->setDefaultLangcode($bundle_settings['settings']['language']['langcode'])
|
||||
->setLanguageAlterable($bundle_settings['settings']['language']['language_alterable'])
|
||||
->save();
|
||||
|
|
|
@ -30,50 +30,50 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
|
||||
$predefined_languages['custom'] = $this->t('Custom language...');
|
||||
$predefined_default = $form_state->getValue('predefined_langcode', key($predefined_languages));
|
||||
$form['predefined_langcode'] = array(
|
||||
$form['predefined_langcode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Language name'),
|
||||
'#default_value' => $predefined_default,
|
||||
'#options' => $predefined_languages,
|
||||
);
|
||||
$form['predefined_submit'] = array(
|
||||
];
|
||||
$form['predefined_submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add language'),
|
||||
'#name' => 'add_language',
|
||||
'#limit_validation_errors' => array(array('predefined_langcode'), array('predefined_submit')),
|
||||
'#states' => array(
|
||||
'invisible' => array(
|
||||
'select#edit-predefined-langcode' => array('value' => 'custom'),
|
||||
),
|
||||
),
|
||||
'#validate' => array('::validatePredefined'),
|
||||
'#submit' => array('::submitForm', '::save'),
|
||||
'#limit_validation_errors' => [['predefined_langcode'], ['predefined_submit']],
|
||||
'#states' => [
|
||||
'invisible' => [
|
||||
'select#edit-predefined-langcode' => ['value' => 'custom'],
|
||||
],
|
||||
],
|
||||
'#validate' => ['::validatePredefined'],
|
||||
'#submit' => ['::submitForm', '::save'],
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
$custom_language_states_conditions = array(
|
||||
'select#edit-predefined-langcode' => array('value' => 'custom'),
|
||||
);
|
||||
$form['custom_language'] = array(
|
||||
$custom_language_states_conditions = [
|
||||
'select#edit-predefined-langcode' => ['value' => 'custom'],
|
||||
];
|
||||
$form['custom_language'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
'visible' => $custom_language_states_conditions,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->commonForm($form['custom_language']);
|
||||
$form['custom_language']['langcode']['#states'] = array(
|
||||
$form['custom_language']['langcode']['#states'] = [
|
||||
'required' => $custom_language_states_conditions,
|
||||
);
|
||||
$form['custom_language']['label']['#states'] = array(
|
||||
];
|
||||
$form['custom_language']['label']['#states'] = [
|
||||
'required' => $custom_language_states_conditions,
|
||||
);
|
||||
$form['custom_language']['submit'] = array(
|
||||
];
|
||||
$form['custom_language']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add custom language'),
|
||||
'#name' => 'add_custom_language',
|
||||
'#validate' => array('::validateCustom'),
|
||||
'#submit' => array('::submitForm', '::save'),
|
||||
);
|
||||
'#validate' => ['::validateCustom'],
|
||||
'#submit' => ['::submitForm', '::save'],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -84,14 +84,14 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
public function save(array $form, FormStateInterface $form_state) {
|
||||
parent::save($form, $form_state);
|
||||
|
||||
$t_args = array('%language' => $this->entity->label(), '%langcode' => $this->entity->id());
|
||||
$t_args = ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()];
|
||||
$this->logger('language')->notice('The %language (%langcode) language has been created.', $t_args);
|
||||
drupal_set_message($this->t('The language %language has been created and can now be used.', $t_args));
|
||||
|
||||
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>.', [':block-admin' => $this->url('block.admin_display')]));
|
||||
}
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
*/
|
||||
public function actions(array $form, FormStateInterface $form_state) {
|
||||
// No actions needed.
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
$this->validateCommon($form['custom_language'], $form_state);
|
||||
|
||||
if ($language = $this->languageManager->getLanguage($langcode)) {
|
||||
$form_state->setErrorByName('langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode)));
|
||||
$form_state->setErrorByName('langcode', $this->t('The language %language (%langcode) already exists.', ['%language' => $language->getName(), '%langcode' => $langcode]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -132,7 +132,7 @@ class LanguageAddForm extends LanguageFormBase {
|
|||
}
|
||||
else {
|
||||
if ($language = $this->languageManager->getLanguage($langcode)) {
|
||||
$form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode)));
|
||||
$form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', ['%language' => $language->getName(), '%langcode' => $langcode]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ class LanguageDeleteForm extends EntityDeleteForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDeletionMessage() {
|
||||
return $this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()));
|
||||
return $this->t('The %language (%langcode) language has been removed.', ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function logDeletionMessage() {
|
||||
$this->logger('language')->notice('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()));
|
||||
$this->logger('language')->notice('The %language (%langcode) language has been removed.', ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ class LanguageEditForm extends LanguageFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions(array $form, FormStateInterface $form_state) {
|
||||
$actions['submit'] = array(
|
||||
$actions['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save language'),
|
||||
'#validate' => array('::validateCommon'),
|
||||
'#submit' => array('::submitForm', '::save'),
|
||||
);
|
||||
'#validate' => ['::validateCommon'],
|
||||
'#submit' => ['::submitForm', '::save'],
|
||||
];
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class LanguageEditForm extends LanguageFormBase {
|
|||
public function save(array $form, FormStateInterface $form_state) {
|
||||
parent::save($form, $form_state);
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
$this->logger('language')->notice('The %language (%langcode) language has been updated.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()));
|
||||
$this->logger('language')->notice('The %language (%langcode) language has been updated.', ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,45 +47,45 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
/* @var $language \Drupal\language\ConfigurableLanguageInterface */
|
||||
$language = $this->entity;
|
||||
if ($language->getId()) {
|
||||
$form['langcode_view'] = array(
|
||||
$form['langcode_view'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Language code'),
|
||||
'#markup' => $language->id()
|
||||
);
|
||||
$form['langcode'] = array(
|
||||
];
|
||||
$form['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $language->id()
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Language code'),
|
||||
'#maxlength' => 12,
|
||||
'#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>', [':w3ctags' => 'http://www.w3.org/International/articles/language-tags/']),
|
||||
];
|
||||
}
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Language name'),
|
||||
'#maxlength' => 64,
|
||||
'#default_value' => $language->label(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['direction'] = array(
|
||||
];
|
||||
$form['direction'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Direction'),
|
||||
'#required' => TRUE,
|
||||
'#description' => $this->t('Direction that text in this language is presented.'),
|
||||
'#default_value' => $language->getDirection(),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
LanguageInterface::DIRECTION_LTR => $this->t('Left to right'),
|
||||
LanguageInterface::DIRECTION_RTL => $this->t('Right to left'),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -96,13 +96,13 @@ 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>.', [
|
||||
'%field' => $form['langcode']['#title'],
|
||||
':url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
]));
|
||||
}
|
||||
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'])));
|
||||
$form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', ['%field' => $form['label']['#title']]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete %browser_langcode?', array('%browser_langcode' => $this->browserLangcode));
|
||||
return $this->t('Are you sure you want to delete %browser_langcode?', ['%browser_langcode' => $this->browserLangcode]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,9 +68,9 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
|
|||
->clear('map.' . $this->browserLangcode)
|
||||
->save();
|
||||
|
||||
$args = array(
|
||||
$args = [
|
||||
'%browser' => $this->browserLangcode,
|
||||
);
|
||||
];
|
||||
|
||||
$this->logger('language')->notice('The browser language detection mapping for the %browser browser language code has been deleted.', $args);
|
||||
|
||||
|
|
|
@ -60,12 +60,12 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form = array();
|
||||
$form = [];
|
||||
|
||||
// Initialize a language list to the ones available, including English.
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
|
||||
$existing_languages = array();
|
||||
$existing_languages = [];
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$existing_languages[$langcode] = $language->getName();
|
||||
}
|
||||
|
@ -77,10 +77,10 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
$language_options = $this->languageManager->getStandardLanguageListWithoutConfigured();
|
||||
}
|
||||
else {
|
||||
$language_options = array(
|
||||
$language_options = [
|
||||
(string) $this->t('Existing languages') => $existing_languages,
|
||||
(string) $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['mappings'] = [
|
||||
|
@ -96,24 +96,24 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
|
||||
$mappings = $this->language_get_browser_drupal_langcode_mappings();
|
||||
foreach ($mappings as $browser_langcode => $drupal_langcode) {
|
||||
$form['mappings'][$browser_langcode] = array(
|
||||
'browser_langcode' => array(
|
||||
$form['mappings'][$browser_langcode] = [
|
||||
'browser_langcode' => [
|
||||
'#title' => $this->t('Browser language code'),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $browser_langcode,
|
||||
'#size' => 20,
|
||||
'#required' => TRUE,
|
||||
),
|
||||
'drupal_langcode' => array(
|
||||
],
|
||||
'drupal_langcode' => [
|
||||
'#title' => $this->t('Site language'),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'select',
|
||||
'#options' => $language_options,
|
||||
'#default_value' => $drupal_langcode,
|
||||
'#required' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Operations column.
|
||||
$form['mappings'][$browser_langcode]['operations'] = [
|
||||
'#type' => 'operations',
|
||||
|
@ -126,22 +126,22 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
}
|
||||
|
||||
// Add empty row.
|
||||
$form['new_mapping'] = array(
|
||||
$form['new_mapping'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Add a new mapping'),
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['new_mapping']['browser_langcode'] = array(
|
||||
];
|
||||
$form['new_mapping']['browser_langcode'] = [
|
||||
'#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>', [':w3ctags' => 'http://www.w3.org/International/articles/language-tags/']),
|
||||
'#size' => 20,
|
||||
);
|
||||
$form['new_mapping']['drupal_langcode'] = array(
|
||||
];
|
||||
$form['new_mapping']['drupal_langcode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Site language'),
|
||||
'#options' => $language_options,
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
// Array to check if all browser language codes are unique.
|
||||
$unique_values = array();
|
||||
$unique_values = [];
|
||||
|
||||
// Check all mappings.
|
||||
if ($form_state->hasValue('mappings')) {
|
||||
|
@ -207,7 +207,7 @@ class NegotiationBrowserForm extends ConfigFormBase {
|
|||
protected function language_get_browser_drupal_langcode_mappings() {
|
||||
$config = $this->config('language.mappings');
|
||||
if ($config->isNew()) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
return $config->get('map');
|
||||
}
|
||||
|
|
|
@ -124,12 +124,12 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$configurable = $this->languageTypes->get('configurable');
|
||||
|
||||
$form = array(
|
||||
$form = [
|
||||
'#theme' => 'language_negotiation_configure_form',
|
||||
'#language_types_info' => $this->languageManager->getDefinedLanguageTypesInfo(),
|
||||
'#language_negotiation_info' => $this->negotiator->getNegotiationMethods(),
|
||||
);
|
||||
$form['#language_types'] = array();
|
||||
];
|
||||
$form['#language_types'] = [];
|
||||
|
||||
foreach ($form['#language_types_info'] as $type => $info) {
|
||||
// Show locked language types only if they are configurable.
|
||||
|
@ -142,12 +142,12 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
$this->configureFormTable($form, $type);
|
||||
}
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#button_type' => 'primary',
|
||||
'#value' => $this->t('Save settings'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -159,17 +159,17 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
$configurable_types = $form['#language_types'];
|
||||
|
||||
$stored_values = $this->languageTypes->get('configurable');
|
||||
$customized = array();
|
||||
$method_weights_type = array();
|
||||
$customized = [];
|
||||
$method_weights_type = [];
|
||||
|
||||
foreach ($configurable_types as $type) {
|
||||
$customized[$type] = in_array($type, $stored_values);
|
||||
$method_weights = array();
|
||||
$enabled_methods = $form_state->getValue(array($type, 'enabled'));
|
||||
$method_weights = [];
|
||||
$enabled_methods = $form_state->getValue([$type, 'enabled']);
|
||||
$enabled_methods[LanguageNegotiationSelected::METHOD_ID] = TRUE;
|
||||
$method_weights_input = $form_state->getValue(array($type, 'weight'));
|
||||
if ($form_state->hasValue(array($type, 'configurable'))) {
|
||||
$customized[$type] = !$form_state->isValueEmpty(array($type, 'configurable'));
|
||||
$method_weights_input = $form_state->getValue([$type, 'weight']);
|
||||
if ($form_state->hasValue([$type, 'configurable'])) {
|
||||
$customized[$type] = !$form_state->isValueEmpty([$type, 'configurable']);
|
||||
}
|
||||
|
||||
foreach ($method_weights_input as $method_id => $weight) {
|
||||
|
@ -216,33 +216,33 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
protected function configureFormTable(array &$form, $type) {
|
||||
$info = $form['#language_types_info'][$type];
|
||||
|
||||
$table_form = array(
|
||||
'#title' => $this->t('@type language detection', array('@type' => $info['name'])),
|
||||
$table_form = [
|
||||
'#title' => $this->t('@type language detection', ['@type' => $info['name']]),
|
||||
'#tree' => TRUE,
|
||||
'#description' => $info['description'],
|
||||
'#language_negotiation_info' => array(),
|
||||
'#language_negotiation_info' => [],
|
||||
'#show_operations' => FALSE,
|
||||
'weight' => array('#tree' => TRUE),
|
||||
);
|
||||
'weight' => ['#tree' => TRUE],
|
||||
];
|
||||
// Only show configurability checkbox for the unlocked language types.
|
||||
if (empty($info['locked'])) {
|
||||
$configurable = $this->languageTypes->get('configurable');
|
||||
$table_form['configurable'] = array(
|
||||
$table_form['configurable'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Customize %language_name language detection to differ from Interface text language detection settings', array('%language_name' => $info['name'])),
|
||||
'#title' => $this->t('Customize %language_name language detection to differ from Interface text language detection settings', ['%language_name' => $info['name']]),
|
||||
'#default_value' => in_array($type, $configurable),
|
||||
'#attributes' => array('class' => array('language-customization-checkbox')),
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
'#attributes' => ['class' => ['language-customization-checkbox']],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'language/drupal.language.admin'
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$negotiation_info = $form['#language_negotiation_info'];
|
||||
$enabled_methods = $this->languageTypes->get('negotiation.' . $type . '.enabled') ?: array();
|
||||
$methods_weight = $this->languageTypes->get('negotiation.' . $type . '.method_weights') ?: array();
|
||||
$enabled_methods = $this->languageTypes->get('negotiation.' . $type . '.enabled') ?: [];
|
||||
$methods_weight = $this->languageTypes->get('negotiation.' . $type . '.method_weights') ?: [];
|
||||
|
||||
// Add missing data to the methods lists.
|
||||
foreach ($negotiation_info as $method_id => $method) {
|
||||
|
@ -272,44 +272,44 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
$table_form['#language_negotiation_info'][$method_id] = $method;
|
||||
$method_name = $method['name'];
|
||||
|
||||
$table_form['weight'][$method_id] = array(
|
||||
$table_form['weight'][$method_id] = [
|
||||
'#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', ['@title' => Unicode::strtolower($method_name)]),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $weight,
|
||||
'#attributes' => array('class' => array("language-method-weight-$type")),
|
||||
'#attributes' => ['class' => ["language-method-weight-$type"]],
|
||||
'#delta' => 20,
|
||||
);
|
||||
];
|
||||
|
||||
$table_form['title'][$method_id] = array('#plain_text' => $method_name);
|
||||
$table_form['title'][$method_id] = ['#plain_text' => $method_name];
|
||||
|
||||
$table_form['enabled'][$method_id] = array(
|
||||
$table_form['enabled'][$method_id] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Enable @title language detection method', array('@title' => Unicode::strtolower($method_name))),
|
||||
'#title' => $this->t('Enable @title language detection method', ['@title' => Unicode::strtolower($method_name)]),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $enabled,
|
||||
);
|
||||
];
|
||||
if ($method_id === LanguageNegotiationSelected::METHOD_ID) {
|
||||
$table_form['enabled'][$method_id]['#default_value'] = TRUE;
|
||||
$table_form['enabled'][$method_id]['#attributes'] = array('disabled' => 'disabled');
|
||||
$table_form['enabled'][$method_id]['#attributes'] = ['disabled' => 'disabled'];
|
||||
}
|
||||
|
||||
$table_form['description'][$method_id] = array('#markup' => $method['description']);
|
||||
$table_form['description'][$method_id] = ['#markup' => $method['description']];
|
||||
|
||||
$config_op = array();
|
||||
$config_op = [];
|
||||
if (isset($method['config_route_name'])) {
|
||||
$config_op['configure'] = array(
|
||||
$config_op['configure'] = [
|
||||
'title' => $this->t('Configure'),
|
||||
'url' => Url::fromRoute($method['config_route_name']),
|
||||
);
|
||||
];
|
||||
// If there is at least one operation enabled show the operation
|
||||
// column.
|
||||
$table_form['#show_operations'] = TRUE;
|
||||
}
|
||||
$table_form['operation'][$method_id] = array(
|
||||
$table_form['operation'][$method_id] = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $config_op,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
$form[$type] = $table_form;
|
||||
|
@ -324,7 +324,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
|
|||
*/
|
||||
protected function disableLanguageSwitcher(array $language_types) {
|
||||
$theme = $this->themeHandler->getDefault();
|
||||
$blocks = $this->blockStorage->loadByProperties(array('theme' => $theme));
|
||||
$blocks = $this->blockStorage->loadByProperties(['theme' => $theme]);
|
||||
foreach ($language_types as $language_type) {
|
||||
foreach ($blocks as $block) {
|
||||
if ($block->getPluginId() == 'language_block:' . $language_type) {
|
||||
|
|
|
@ -30,12 +30,12 @@ class NegotiationSelectedForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('language.negotiation');
|
||||
$form['selected_langcode'] = array(
|
||||
$form['selected_langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => $this->t('Language'),
|
||||
'#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_SITE_DEFAULT,
|
||||
'#default_value' => $config->get('selected_langcode'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ class NegotiationSessionForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('language.negotiation');
|
||||
$form['language_negotiation_session_param'] = array(
|
||||
$form['language_negotiation_session_param'] = [
|
||||
'#title' => $this->t('Request/session parameter'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $config->get('session.parameter'),
|
||||
'#description' => $this->t('Name of the request/session parameter used to determine the desired language.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form_state->setRedirect('language.negotiation');
|
||||
|
||||
|
|
|
@ -66,63 +66,63 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
global $base_url;
|
||||
$config = $this->config('language.negotiation');
|
||||
|
||||
$form['language_negotiation_url_part'] = array(
|
||||
$form['language_negotiation_url_part'] = [
|
||||
'#title' => $this->t('Part of the URL that determines language'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
LanguageNegotiationUrl::CONFIG_PATH_PREFIX => $this->t('Path prefix'),
|
||||
LanguageNegotiationUrl::CONFIG_DOMAIN => $this->t('Domain'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $config->get('url.source'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['prefix'] = array(
|
||||
$form['prefix'] = [
|
||||
'#type' => 'details',
|
||||
'#tree' => TRUE,
|
||||
'#title' => $this->t('Path prefix configuration'),
|
||||
'#open' => TRUE,
|
||||
'#description' => $this->t('Language codes or other custom text to use as a path prefix for URL language detection. For the selected fallback language, this value may be left blank. <strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "deutsch" as the path prefix code for German results in URLs like "example.com/deutsch/contact".'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="language_negotiation_url_part"]' => array(
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="language_negotiation_url_part"]' => [
|
||||
'value' => (string) LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['domain'] = array(
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['domain'] = [
|
||||
'#type' => 'details',
|
||||
'#tree' => TRUE,
|
||||
'#title' => $this->t('Domain configuration'),
|
||||
'#open' => TRUE,
|
||||
'#description' => $this->t('The domain names to use for these languages. <strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "de.example.com" as language domain for German will result in a URL like "http://de.example.com/contact".'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="language_negotiation_url_part"]' => array(
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="language_negotiation_url_part"]' => [
|
||||
'value' => (string) LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
$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(
|
||||
$t_args = ['%language' => $language->getName(), '%langcode' => $language->getId()];
|
||||
$form['prefix'][$langcode] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $language->isDefault() ? $this->t('%language (%langcode) path prefix (Default language)', $t_args) : $this->t('%language (%langcode) path prefix', $t_args),
|
||||
'#maxlength' => 64,
|
||||
'#default_value' => isset($prefixes[$langcode]) ? $prefixes[$langcode] : '',
|
||||
'#field_prefix' => $base_url . '/',
|
||||
);
|
||||
$form['domain'][$langcode] = array(
|
||||
];
|
||||
$form['domain'][$langcode] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('%language (%langcode) domain', array('%language' => $language->getName(), '%langcode' => $language->getId())),
|
||||
'#title' => $this->t('%language (%langcode) domain', ['%language' => $language->getName(), '%langcode' => $language->getId()]),
|
||||
'#maxlength' => 128,
|
||||
'#default_value' => isset($domains[$langcode]) ? $domains[$langcode] : '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form_state->setRedirect('language.negotiation');
|
||||
|
@ -143,7 +143,7 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
$default_langcode = $this->languageManager->getDefaultLanguage()->getId();
|
||||
}
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$value = $form_state->getValue(array('prefix', $langcode));
|
||||
$value = $form_state->getValue(['prefix', $langcode]);
|
||||
if ($value === '') {
|
||||
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,
|
||||
|
@ -161,35 +161,35 @@ class NegotiationUrlForm extends ConfigFormBase {
|
|||
elseif (isset($count[$value]) && $count[$value] > 1) {
|
||||
// Throw a form error if there are two languages with the same
|
||||
// domain/prefix.
|
||||
$form_state->setErrorByName("prefix][$langcode", $this->t('The prefix for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value)));
|
||||
$form_state->setErrorByName("prefix][$langcode", $this->t('The prefix for %language, %value, is not unique.', ['%language' => $language->getName(), '%value' => $value]));
|
||||
}
|
||||
}
|
||||
|
||||
// Count repeated values for uniqueness check.
|
||||
$count = array_count_values($form_state->getValue('domain'));
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$value = $form_state->getValue(array('domain', $langcode));
|
||||
$value = $form_state->getValue(['domain', $langcode]);
|
||||
|
||||
if ($value === '') {
|
||||
if ($form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_DOMAIN) {
|
||||
// Throw a form error if the domain is blank for a non-default language,
|
||||
// although it is required for selected negotiation type.
|
||||
$form_state->setErrorByName("domain][$langcode", $this->t('The domain may not be left blank for %language.', array('%language' => $language->getName())));
|
||||
$form_state->setErrorByName("domain][$langcode", $this->t('The domain may not be left blank for %language.', ['%language' => $language->getName()]));
|
||||
}
|
||||
}
|
||||
elseif (isset($count[$value]) && $count[$value] > 1) {
|
||||
// Throw a form error if there are two languages with the same
|
||||
// domain/domain.
|
||||
$form_state->setErrorByName("domain][$langcode", $this->t('The domain for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value)));
|
||||
$form_state->setErrorByName("domain][$langcode", $this->t('The domain for %language, %value, is not unique.', ['%language' => $language->getName(), '%value' => $value]));
|
||||
}
|
||||
}
|
||||
|
||||
// Domain names should not contain protocol and/or ports.
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$value = $form_state->getValue(array('domain', $langcode));
|
||||
$value = $form_state->getValue(['domain', $langcode]);
|
||||
if (!empty($value)) {
|
||||
// Ensure we have exactly one protocol when checking the hostname.
|
||||
$host = 'http://' . str_replace(array('http://', 'https://'), '', $value);
|
||||
$host = 'http://' . str_replace(['http://', 'https://'], '', $value);
|
||||
if (parse_url($host, PHP_URL_HOST) != $value) {
|
||||
$form_state->setErrorByName("domain][$langcode", $this->t('The domain for %language may only contain the domain name, not a trailing slash, protocol and/or port.', ['%language' => $language->getName()]));
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
if (!isset($this->multilingual)) {
|
||||
$this->multilingual = $this->languageManager->isMultilingual();
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
|
|||
*/
|
||||
protected function initProcessors($scope) {
|
||||
$interface = '\Drupal\Core\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
|
||||
$this->processors[$scope] = array();
|
||||
$this->processors[$scope] = [];
|
||||
$weights = [];
|
||||
foreach ($this->languageManager->getLanguageTypes() as $type) {
|
||||
foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
|
||||
|
@ -174,7 +174,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
|
|||
* Resets the collected processors instances.
|
||||
*/
|
||||
public function reset() {
|
||||
$this->processors = array();
|
||||
$this->processors = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ class LanguageAccessControlHandler extends EntityAccessControlHandler {
|
|||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
|
||||
case 'update':
|
||||
/* @var \Drupal\Core\Language\LanguageInterface $entity */
|
||||
return AccessResult::allowedIf(!$entity->isLocked())->addCacheableDependency($entity)
|
||||
|
|
|
@ -71,11 +71,11 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function load() {
|
||||
$entities = $this->storage->loadByProperties(array('locked' => FALSE));
|
||||
$entities = $this->storage->loadByProperties(['locked' => FALSE]);
|
||||
|
||||
// Sort the entities using the entity class's sort() method.
|
||||
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
|
||||
uasort($entities, array($this->entityType->getClass(), 'sort'));
|
||||
uasort($entities, [$this->entityType->getClass(), 'sort']);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
|
@ -90,10 +90,10 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header = array(
|
||||
$header = [
|
||||
'label' => t('Name'),
|
||||
'default' => t('Default'),
|
||||
) + parent::buildHeader();
|
||||
] + parent::buildHeader();
|
||||
return $header;
|
||||
}
|
||||
|
||||
|
@ -102,14 +102,14 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $entity->label();
|
||||
$row['default'] = array(
|
||||
$row['default'] = [
|
||||
'#type' => 'radio',
|
||||
'#parents' => array('site_default_language'),
|
||||
'#title' => t('Set @title as default', array('@title' => $entity->label())),
|
||||
'#parents' => ['site_default_language'],
|
||||
'#title' => t('Set @title as default', ['@title' => $entity->label()]),
|
||||
'#title_display' => 'invisible',
|
||||
'#return_value' => $entity->id(),
|
||||
'#id' => 'edit-site-default-language-' . $entity->id(),
|
||||
);
|
||||
];
|
||||
// Mark the right language as default in the form.
|
||||
if ($entity->id() == $this->languageManager->getDefaultLanguage()->getId()) {
|
||||
$row['default']['#default_value'] = $entity->id();
|
||||
|
@ -157,7 +157,7 @@ class LanguageListBuilder extends DraggableListBuilder {
|
|||
drupal_set_message(t('Configuration saved.'));
|
||||
// Force the redirection to the page with the language we have just
|
||||
// selected as default.
|
||||
$form_state->setRedirectUrl($this->entities[$new_id]->urlInfo('collection', array('language' => $this->entities[$new_id])));
|
||||
$form_state->setRedirectUrl($this->entities[$new_id]->urlInfo('collection', ['language' => $this->entities[$new_id]]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
*
|
||||
* @var \Drupal\Core\Language\LanguageInterface[]
|
||||
*/
|
||||
protected $negotiatedLanguages = array();
|
||||
protected $negotiatedLanguages = [];
|
||||
|
||||
/**
|
||||
* Constructs a new LanguageNegotiator object.
|
||||
|
@ -105,8 +105,8 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
$this->negotiatedLanguages = array();
|
||||
$this->methods = array();
|
||||
$this->negotiatedLanguages = [];
|
||||
$this->methods = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,7 +150,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
$method_id = static::METHOD_ID;
|
||||
}
|
||||
|
||||
return array($method_id => $language);
|
||||
return [$method_id => $language];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
* An array of enabled detection methods for the provided language type.
|
||||
*/
|
||||
protected function getEnabledNegotiators($type) {
|
||||
return $this->configFactory->get('language.types')->get('negotiation.' . $type . '.enabled') ?: array();
|
||||
return $this->configFactory->get('language.types')->get('negotiation.' . $type . '.enabled') ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
*/
|
||||
public function getNegotiationMethodInstance($method_id) {
|
||||
if (!isset($this->methods[$method_id])) {
|
||||
$instance = $this->negotiatorManager->createInstance($method_id, array());
|
||||
$instance = $this->negotiatorManager->createInstance($method_id, []);
|
||||
$instance->setLanguageManager($this->languageManager);
|
||||
$instance->setConfig($this->configFactory);
|
||||
$instance->setCurrentUser($this->currentUser);
|
||||
|
@ -229,7 +229,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
*/
|
||||
public function isNegotiationMethodEnabled($method_id, $type = NULL) {
|
||||
$enabled = FALSE;
|
||||
$language_types = !empty($type) ? array($type) : $this->languageManager->getLanguageTypes();
|
||||
$language_types = !empty($type) ? [$type] : $this->languageManager->getLanguageTypes();
|
||||
|
||||
foreach ($language_types as $type) {
|
||||
$enabled_methods = $this->getEnabledNegotiators($type);
|
||||
|
@ -245,7 +245,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function saveConfiguration($type, $enabled_methods) {
|
||||
public function saveConfiguration($type, $enabled_methods) {
|
||||
// As configurable language types might have changed, we reset the cache.
|
||||
$this->languageManager->reset();
|
||||
$definitions = $this->getNegotiationMethods();
|
||||
|
@ -274,7 +274,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function purgeConfiguration() {
|
||||
public function purgeConfiguration() {
|
||||
// Ensure that we are getting the defined language negotiation information.
|
||||
// An invocation of \Drupal\Core\Extension\ModuleInstaller::install() or
|
||||
// \Drupal\Core\Extension\ModuleInstaller::uninstall() could invalidate the
|
||||
|
@ -289,7 +289,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function updateConfiguration(array $types) {
|
||||
public function updateConfiguration(array $types) {
|
||||
// Ensure that we are getting the defined language negotiation information.
|
||||
// An invocation of \Drupal\Core\Extension\ModuleInstaller::install() or
|
||||
// \Drupal\Core\Extension\ModuleInstaller::uninstall() could invalidate the
|
||||
|
@ -297,7 +297,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
$this->negotiatorManager->clearCachedDefinitions();
|
||||
$this->languageManager->reset();
|
||||
|
||||
$language_types = array();
|
||||
$language_types = [];
|
||||
$language_types_info = $this->languageManager->getDefinedLanguageTypesInfo();
|
||||
$method_definitions = $this->getNegotiationMethods();
|
||||
|
||||
|
@ -316,7 +316,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
// default language negotiation settings, we use the values
|
||||
// negotiated for the interface language which, should always be
|
||||
// available.
|
||||
$method_weights = array(LanguageNegotiationUI::METHOD_ID);
|
||||
$method_weights = [LanguageNegotiationUI::METHOD_ID];
|
||||
$method_weights = array_flip($method_weights);
|
||||
$this->saveConfiguration($type, $method_weights);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
// If the language type is locked we can just store its default language
|
||||
// negotiation settings if it has some, since it is not configurable.
|
||||
if ($has_default_settings) {
|
||||
$method_weights = array();
|
||||
$method_weights = [];
|
||||
// Default settings are in $info['fixed'].
|
||||
|
||||
foreach ($info['fixed'] as $weight => $method_id) {
|
||||
|
@ -351,10 +351,10 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
|
|||
}
|
||||
|
||||
// Store the language type configuration.
|
||||
$config = array(
|
||||
$config = [
|
||||
'configurable' => array_keys(array_filter($language_types)),
|
||||
'all' => array_keys($language_types),
|
||||
);
|
||||
];
|
||||
$this->languageManager->saveLanguageTypesConfiguration($config);
|
||||
}
|
||||
|
||||
|
|
|
@ -187,12 +187,12 @@ interface LanguageNegotiatorInterface {
|
|||
* @param int[] $enabled_methods
|
||||
* An array of language negotiation method weights keyed by method ID.
|
||||
*/
|
||||
function saveConfiguration($type, $enabled_methods);
|
||||
public function saveConfiguration($type, $enabled_methods);
|
||||
|
||||
/**
|
||||
* Resave the configuration to purge missing negotiation methods.
|
||||
*/
|
||||
function purgeConfiguration();
|
||||
public function purgeConfiguration();
|
||||
|
||||
/**
|
||||
* Updates the configuration based on the given language types.
|
||||
|
@ -204,6 +204,6 @@ interface LanguageNegotiatorInterface {
|
|||
* @param string[] $types
|
||||
* An array of configurable language types.
|
||||
*/
|
||||
function updateConfiguration(array $types);
|
||||
public function updateConfiguration(array $types);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ class LanguageServiceProvider extends ServiceProviderBase {
|
|||
->addArgument(new Reference('current_user'));
|
||||
|
||||
$container->register('path_processor_language', 'Drupal\language\HttpKernel\PathProcessorLanguage')
|
||||
->addTag('path_processor_inbound', array('priority' => 300))
|
||||
->addTag('path_processor_outbound', array('priority' => 100))
|
||||
->addTag('path_processor_inbound', ['priority' => 300])
|
||||
->addTag('path_processor_outbound', ['priority' => 100])
|
||||
->addArgument(new Reference('config.factory'))
|
||||
->addArgument(new Reference('language_manager'))
|
||||
->addArgument(new Reference('language_negotiator'))
|
||||
|
@ -54,13 +54,6 @@ class LanguageServiceProvider extends ServiceProviderBase {
|
|||
$container->setParameter('language.default_values', $default_language_values);
|
||||
}
|
||||
|
||||
// For monolingual sites, we explicitly set the default language for the
|
||||
// language config override service as there is no language negotiation.
|
||||
if (!$this->isMultilingual()) {
|
||||
$container->getDefinition('language.config_factory_override')
|
||||
->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,22 +84,22 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$build = array();
|
||||
$build = [];
|
||||
$route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>';
|
||||
$type = $this->getDerivativeId();
|
||||
$links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
|
||||
|
||||
if (isset($links->links)) {
|
||||
$build = array(
|
||||
$build = [
|
||||
'#theme' => 'links__language_block',
|
||||
'#links' => $links->links,
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
'#attributes' => [
|
||||
'class' => [
|
||||
"language-switcher-{$links->method_id}",
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'#set_active_class' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
|
|
@ -68,23 +68,23 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
if ($this->languageManager->isMultilingual()) {
|
||||
// Fetch languages.
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
$langcodes_options = array();
|
||||
$langcodes_options = [];
|
||||
foreach ($languages as $language) {
|
||||
$langcodes_options[$language->getId()] = $language->getName();
|
||||
}
|
||||
$form['langcodes'] = array(
|
||||
$form['langcodes'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Language selection'),
|
||||
'#default_value' => $this->configuration['langcodes'],
|
||||
'#options' => $langcodes_options,
|
||||
'#description' => $this->t('Select languages to enforce. If none are selected, all languages will be allowed.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['langcodes'] = array(
|
||||
$form['langcodes'] = [
|
||||
'#type' => 'value',
|
||||
'#default_value' => $this->configuration['langcodes'],
|
||||
);
|
||||
];
|
||||
}
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
$result[$item->getId()] = $item->getName();
|
||||
}
|
||||
return $result;
|
||||
}, array());
|
||||
}, []);
|
||||
|
||||
// If we have more than one language selected, separate them by commas.
|
||||
if (count($this->configuration['langcodes']) > 1) {
|
||||
|
@ -122,9 +122,9 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
$languages = array_pop($language_names);
|
||||
}
|
||||
if (!empty($this->configuration['negate'])) {
|
||||
return t('The language is not @languages.', array('@languages' => $languages));
|
||||
return t('The language is not @languages.', ['@languages' => $languages]);
|
||||
}
|
||||
return t('The language is @languages.', array('@languages' => $languages));
|
||||
return t('The language is @languages.', ['@languages' => $languages]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,7 +144,7 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array('langcodes' => array()) + parent::defaultConfiguration();
|
||||
return ['langcodes' => []] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,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)', ['@type' => $info[$type]['name']]);
|
||||
}
|
||||
// If there is just one configurable type then change the title of the
|
||||
// block.
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\language\Plugin\LanguageNegotiation;
|
||||
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
|
||||
|
@ -118,20 +117,8 @@ class LanguageNegotiationContentEntity extends LanguageNegotiationMethodBase imp
|
|||
unset($options['language']);
|
||||
}
|
||||
|
||||
if (isset($options['query']) && is_string($options['query'])) {
|
||||
$query = [];
|
||||
parse_str($options['query'], $query);
|
||||
$options['query'] = $query;
|
||||
}
|
||||
else {
|
||||
$options['query'] = [];
|
||||
}
|
||||
|
||||
if (!isset($options['query'][static::QUERY_PARAMETER])) {
|
||||
$query_addon = [static::QUERY_PARAMETER => $langcode];
|
||||
$options['query'] += $query_addon;
|
||||
// @todo Remove this once https://www.drupal.org/node/2507005 lands.
|
||||
$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($query_addon);
|
||||
$options['query'][static::QUERY_PARAMETER] = $langcode;
|
||||
}
|
||||
|
||||
if ($bubbleable_metadata) {
|
||||
|
@ -276,7 +263,7 @@ class LanguageNegotiationContentEntity extends LanguageNegotiationMethodBase imp
|
|||
$this->contentEntityPaths = [];
|
||||
$entity_types = $this->entityManager->getDefinitions();
|
||||
foreach ($entity_types as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->isSubclassOf(ContentEntityInterface::class)) {
|
||||
if ($entity_type->entityClassImplements(ContentEntityInterface::class)) {
|
||||
$entity_paths = array_fill_keys($entity_type->getLinkTemplates(), $entity_type_id);
|
||||
$this->contentEntityPaths = array_merge($this->contentEntityPaths, $entity_paths);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
if ($request) {
|
||||
// The following values are not supposed to change during a single page
|
||||
// request processing.
|
||||
|
@ -102,11 +102,6 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
|
|||
// enabled, and the corresponding option has been set, we must preserve
|
||||
// any explicit user language preference even with cookies disabled.
|
||||
if ($this->queryRewrite) {
|
||||
if (isset($options['query']) && is_string($options['query'])) {
|
||||
$query = array();
|
||||
parse_str($options['query'], $query);
|
||||
$options['query'] = $query;
|
||||
}
|
||||
if (!isset($options['query'][$this->queryParam])) {
|
||||
$options['query'][$this->queryParam] = $this->queryValue;
|
||||
}
|
||||
|
@ -129,24 +124,24 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
|
||||
$links = array();
|
||||
$links = [];
|
||||
$config = $this->config->get('language.negotiation')->get('session');
|
||||
$param = $config['parameter'];
|
||||
$language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $this->languageManager->getCurrentLanguage($type)->getId();
|
||||
$query = array();
|
||||
$query = [];
|
||||
parse_str($request->getQueryString(), $query);
|
||||
|
||||
foreach ($this->languageManager->getNativeLanguages() as $language) {
|
||||
$langcode = $language->getId();
|
||||
$links[$langcode] = array(
|
||||
$links[$langcode] = [
|
||||
// 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')),
|
||||
'attributes' => ['class' => ['language-link']],
|
||||
'query' => $query,
|
||||
);
|
||||
];
|
||||
if ($language_query != $langcode) {
|
||||
$links[$langcode]['query'][$param] = $langcode;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
if (!empty($config['domains'][$language->getId()])) {
|
||||
// Ensure that there is exactly one protocol in the URL when
|
||||
// checking the hostname.
|
||||
$host = 'http://' . str_replace(array('http://', 'https://'), '', $config['domains'][$language->getId()]);
|
||||
$host = 'http://' . str_replace(['http://', 'https://'], '', $config['domains'][$language->getId()]);
|
||||
$host = parse_url($host, PHP_URL_HOST);
|
||||
if ($http_host == $host) {
|
||||
$langcode = $language->getId();
|
||||
|
@ -100,15 +100,18 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
*/
|
||||
public function processInbound($path, Request $request) {
|
||||
$config = $this->config->get('language.negotiation')->get('url');
|
||||
$parts = explode('/', trim($path, '/'));
|
||||
$prefix = array_shift($parts);
|
||||
|
||||
// Search prefix within added languages.
|
||||
foreach ($this->languageManager->getLanguages() as $language) {
|
||||
if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
|
||||
// Rebuild $path with the language removed.
|
||||
$path = '/' . implode('/', $parts);
|
||||
break;
|
||||
if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
|
||||
$parts = explode('/', trim($path, '/'));
|
||||
$prefix = array_shift($parts);
|
||||
|
||||
// Search prefix within added languages.
|
||||
foreach ($this->languageManager->getLanguages() as $language) {
|
||||
if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
|
||||
// Rebuild $path with the language removed.
|
||||
$path = '/' . implode('/', $parts);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +121,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
|
||||
$url_scheme = 'http';
|
||||
$port = 80;
|
||||
if ($request) {
|
||||
|
@ -151,7 +154,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
// retain it below.
|
||||
if (!empty($options['base_url'])) {
|
||||
// The colon in the URL scheme messes up the port checking below.
|
||||
$normalized_base_url = str_replace(array('https://', 'http://'), '', $options['base_url']);
|
||||
$normalized_base_url = str_replace(['https://', 'http://'], '', $options['base_url']);
|
||||
}
|
||||
|
||||
// Ask for an absolute URL with our modified base URL.
|
||||
|
@ -191,20 +194,20 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
|
||||
$links = array();
|
||||
$links = [];
|
||||
$query = $request->query->all();
|
||||
|
||||
foreach ($this->languageManager->getNativeLanguages() as $language) {
|
||||
$links[$language->getId()] = array(
|
||||
$links[$language->getId()] = [
|
||||
// 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')),
|
||||
'attributes' => ['class' => ['language-link']],
|
||||
'query' => $query,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $links;
|
||||
|
|
|
@ -19,7 +19,7 @@ class DefaultLangcode extends Config {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$destination = $row->getDestination();
|
||||
$langcode = $destination['default_langcode'];
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class Language extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'language' => $this->t('The language code.'),
|
||||
'name' => $this->t('The English name of the language.'),
|
||||
'native' => $this->t('The native name of the language.'),
|
||||
|
@ -29,18 +29,18 @@ class Language extends DrupalSqlBase {
|
|||
'prefix' => $this->t('Path prefix used for this language.'),
|
||||
'weight' => $this->t('The language weight when listed.'),
|
||||
'javascript' => $this->t('Location of the JavaScript translation file.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'language' => array(
|
||||
return [
|
||||
'language' => [
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,20 +19,20 @@ class LanguageContentSettings extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
return $this->select('node_type', 't')
|
||||
->fields('t', array(
|
||||
->fields('t', [
|
||||
'type',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'type' => $this->t('Type'),
|
||||
'language_content_type' => $this->t('Multilingual support.'),
|
||||
'i18n_lock_node' => $this->t('Lock language.'),
|
||||
);
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,20 +19,20 @@ class LanguageContentSettings extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
return $this->select('node_type', 't')
|
||||
->fields('t', array(
|
||||
->fields('t', [
|
||||
'type',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'type' => $this->t('Type'),
|
||||
'language_content_type' => $this->t('Multilingual support.'),
|
||||
'i18n_lock_node' => $this->t('Lock language.'),
|
||||
);
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Test administration path based conversion of entities.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class AdminPathEntityConverterLanguageTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('language', 'language_test');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$permissions = array(
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
);
|
||||
$this->drupalLogin($this->drupalCreateUser($permissions));
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the translated and untranslated config entities are loaded properly.
|
||||
*/
|
||||
public function testConfigUsingCurrentLanguage() {
|
||||
\Drupal::languageManager()
|
||||
->getLanguageConfigOverride('es', 'language.entity.es')
|
||||
->set('label', 'Español')
|
||||
->save();
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_current_language/es');
|
||||
$this->assertNoRaw(t('Loaded %label.', array('%label' => 'Spanish')));
|
||||
$this->assertRaw(t('Loaded %label.', array('%label' => 'Español')));
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_original_language/es');
|
||||
$this->assertRaw(t('Loaded %label.', array('%label' => 'Spanish')));
|
||||
$this->assertNoRaw(t('Loaded %label.', array('%label' => 'Español')));
|
||||
}
|
||||
|
||||
}
|
|
@ -19,10 +19,10 @@ class EntityTypeWithoutLanguageFormTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
public static $modules = [
|
||||
'language',
|
||||
'language_test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -31,9 +31,9 @@ class EntityTypeWithoutLanguageFormTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create and log in administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the language settings on block config appears correctly.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBlockSettingsVisibilityTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('block', 'language');
|
||||
|
||||
public function testUnnecessaryLanguageSettingsVisibility() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer blocks'));
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
|
||||
$this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark');
|
||||
$this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
|
||||
$this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
|
||||
$this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
|
||||
$this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests browser language detection.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBrowserDetectionTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('language');
|
||||
|
||||
/**
|
||||
* Tests for adding, editing and deleting mappings between browser language
|
||||
* codes and Drupal language codes.
|
||||
*/
|
||||
function testUIBrowserLanguageMappings() {
|
||||
// User to manage languages.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Check that the configure link exists.
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertLinkByHref('admin/config/regional/language/detection/browser');
|
||||
|
||||
// Check that defaults are loaded from language.mappings.yml.
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser');
|
||||
$this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.');
|
||||
$this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.');
|
||||
|
||||
// Delete zh-cn language code.
|
||||
$browser_langcode = 'zh-cn';
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
|
||||
$message = t('Are you sure you want to delete @browser_langcode?', array(
|
||||
'@browser_langcode' => $browser_langcode,
|
||||
));
|
||||
$this->assertRaw($message);
|
||||
|
||||
// Confirm the delete.
|
||||
$edit = array();
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm'));
|
||||
|
||||
// We need raw here because %browser will add HTML.
|
||||
$t_args = array(
|
||||
'%browser' => $browser_langcode,
|
||||
);
|
||||
$this->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.');
|
||||
|
||||
// Check we went back to the browser negotiation mapping overview.
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
// Check that ch-zn no longer exists.
|
||||
$this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.');
|
||||
|
||||
// Add a new custom mapping.
|
||||
$edit = array(
|
||||
'new_mapping[browser_langcode]' => 'xx',
|
||||
'new_mapping[drupal_langcode]' => 'en',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.');
|
||||
|
||||
// Add the same custom mapping again.
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText('Browser language codes must be unique.');
|
||||
|
||||
// Change browser language code of our custom mapping to zh-sg.
|
||||
$edit = array(
|
||||
'mappings[xx][browser_langcode]' => 'zh-sg',
|
||||
'mappings[xx][drupal_langcode]' => 'en',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText(t('Browser language codes must be unique.'));
|
||||
|
||||
// Change Drupal language code of our custom mapping to zh-hans.
|
||||
$edit = array(
|
||||
'mappings[xx][browser_langcode]' => 'xx',
|
||||
'mappings[xx][drupal_langcode]' => 'zh-hans',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config overrides can be synchronized.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideImportTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'config', 'locale', 'config_translation');
|
||||
|
||||
/**
|
||||
* Tests that language can be enabled and overrides are created during a sync.
|
||||
*/
|
||||
public function testConfigOverrideImport() {
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
/* @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
|
||||
// during a configuration synchronization.
|
||||
\Drupal::service('module_installer')->uninstall(array('language'));
|
||||
// Ensure that the current site has no overrides registered to the
|
||||
// ConfigFactory.
|
||||
$this->rebuildContainer();
|
||||
|
||||
/* @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();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
|
||||
$this->assertEqual('FR default site name', $override->get('name'));
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
|
||||
$this->assertText('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuration events are not fired during a sync of overrides.
|
||||
*/
|
||||
public function testConfigOverrideImportEvents() {
|
||||
// Enable the config_events_test module so we can record events occurring.
|
||||
\Drupal::service('module_installer')->install(array('config_events_test'));
|
||||
$this->rebuildContainer();
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
/* @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_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();
|
||||
$this->rebuildContainer();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// Test that no config save event has been fired during the import because
|
||||
// language configuration overrides do not fire events.
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config schema is correct.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigSchemaTest extends WebTestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'menu_link_content');
|
||||
|
||||
/**
|
||||
* A user with administrative permissions.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create user.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages'));
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the language config schema is valid.
|
||||
*/
|
||||
function testValidLanguageConfigSchema() {
|
||||
// Make sure no language configuration available by default.
|
||||
$config_data = $this->config('language.settings')->get();
|
||||
$this->assertTrue(empty($config_data));
|
||||
|
||||
$settings_path = 'admin/config/regional/content-language';
|
||||
|
||||
// Enable translation for menu link.
|
||||
$edit['entity_types[menu_link_content]'] = TRUE;
|
||||
$edit['settings[menu_link_content][menu_link_content][settings][language][language_alterable]'] = TRUE;
|
||||
|
||||
// Enable translation for user.
|
||||
$edit['entity_types[user]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][language_alterable]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][langcode]'] = 'en';
|
||||
|
||||
$this->drupalPostForm($settings_path, $edit, t('Save configuration'));
|
||||
|
||||
$config_data = $this->config('language.content_settings.menu_link_content.menu_link_content');
|
||||
// Make sure configuration saved correctly.
|
||||
$this->assertTrue($config_data->get('language_alterable'));
|
||||
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), $config_data->getName(), $config_data->get());
|
||||
}
|
||||
|
||||
}
|
|
@ -20,11 +20,11 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('taxonomy', 'node', 'language', 'language_elements_test', 'field_ui');
|
||||
public static $modules = ['taxonomy', 'node', 'language', 'language_elements_test', 'field_ui'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$user = $this->drupalCreateUser(array('access administration pages', 'administer languages', 'administer content types'));
|
||||
$user = $this->drupalCreateUser(['access administration pages', 'administer languages', 'administer content types']);
|
||||
$this->drupalLogin($user);
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,12 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$this->assertFieldChecked('edit-lang-configuration-language-alterable');
|
||||
|
||||
// Test if content type settings have been saved.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => 'Page',
|
||||
'type' => 'page',
|
||||
'language_configuration[langcode]' => 'authors_default',
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/add', $edit, 'Save and manage fields');
|
||||
|
||||
// Make sure the settings are saved when creating the content type.
|
||||
|
@ -80,11 +80,11 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
*/
|
||||
public function testDefaultLangcode() {
|
||||
// Add some custom languages.
|
||||
foreach (array('aa', 'bb', 'cc') as $language_code) {
|
||||
ConfigurableLanguage::create(array(
|
||||
foreach (['aa', 'bb', 'cc'] as $language_code) {
|
||||
ConfigurableLanguage::create([
|
||||
'id' => $language_code,
|
||||
'label' => $this->randomMachineName(),
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
// Fixed language.
|
||||
|
@ -154,14 +154,14 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
// Create the article content type first if the profile used is not the
|
||||
// standard one.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
$admin_user = $this->drupalCreateUser(array('administer content types'));
|
||||
$admin_user = $this->drupalCreateUser(['administer content types']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_configuration[langcode]' => 'current_interface',
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
|
||||
// Check the language default configuration for the articles.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
|
||||
|
@ -169,9 +169,9 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$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.');
|
||||
// Update the article content type by changing the title label.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title_label' => 'Name'
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
|
||||
// Check that we still have the settings for the updated node type.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
|
||||
|
@ -187,19 +187,19 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
// Create the article content type first if the profile used is not the
|
||||
// standard one.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array(
|
||||
$this->drupalCreateContentType([
|
||||
'type' => 'article',
|
||||
'name' => 'Article'
|
||||
));
|
||||
]);
|
||||
}
|
||||
$admin_user = $this->drupalCreateUser(array('administer content types'));
|
||||
$admin_user = $this->drupalCreateUser(['administer content types']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create language configuration for the articles.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_configuration[langcode]' => 'authors_default',
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
|
||||
|
||||
// Check the language default configuration for articles is present.
|
||||
|
@ -207,7 +207,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$this->assertTrue($configuration, 'The language configuration is present.');
|
||||
|
||||
// Delete 'article' bundle.
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/delete', [], t('Delete'));
|
||||
|
||||
// Check that the language configuration has been deleted.
|
||||
\Drupal::entityManager()->getStorage('language_content_settings')->resetCache();
|
||||
|
@ -225,12 +225,12 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
]);
|
||||
$vocabulary->save();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer taxonomy'));
|
||||
$admin_user = $this->drupalCreateUser(['administer taxonomy']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'default_language[langcode]' => 'current_interface',
|
||||
'default_language[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save'));
|
||||
|
||||
// Check the language default configuration.
|
||||
|
@ -239,9 +239,9 @@ class LanguageConfigurationElementTest extends WebTestBase {
|
|||
$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.');
|
||||
// Update the vocabulary.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => 'Nation'
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save'));
|
||||
// Check that we still have the settings for the updated vocabulary.
|
||||
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country');
|
||||
|
|
|
@ -18,18 +18,18 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Functional tests for adding, editing and deleting languages.
|
||||
*/
|
||||
function testLanguageConfiguration() {
|
||||
public function testLanguageConfiguration() {
|
||||
// Ensure the after installing the language module the weight of the English
|
||||
// language is still 0.
|
||||
$this->assertEqual(ConfigurableLanguage::load('en')->getWeight(), 0, 'The English language has a weight of 0.');
|
||||
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Check if the Default English language has no path prefix.
|
||||
|
@ -41,9 +41,9 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button');
|
||||
|
||||
// Add predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, 'Add language');
|
||||
$this->assertText('French');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
@ -63,9 +63,9 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
$this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.');
|
||||
|
||||
// Change the default language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertFieldChecked('edit-site-default-language-fr', 'Default language updated.');
|
||||
|
@ -80,16 +80,16 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
$this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
|
||||
|
||||
// Check that prefix can be changed.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'prefix[fr]' => 'french',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.');
|
||||
|
||||
// Check that the prefix can be removed.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'prefix[fr]' => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->assertNoText(t('The prefix may only be left blank for the selected detection fallback language.'), 'The path prefix can be removed for the default language');
|
||||
|
||||
|
@ -97,24 +97,24 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
$this->config('language.negotiation')->set('selected_langcode', 'fr')->save();
|
||||
// Check that the prefix of a language that is not the negotiation one
|
||||
// cannot be changed to empty string.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'prefix[en]' => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->assertText(t('The prefix may only be left blank for the selected detection fallback language.'));
|
||||
|
||||
// Check that prefix cannot be changed to contain a slash.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'prefix[en]' => 'foo/bar',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
|
||||
|
||||
// Remove English language and add a new Language to check if langcode of
|
||||
// Language entity is 'en'.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'English', '%langcode' => 'en')));
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', ['%language' => 'English', '%langcode' => 'en']));
|
||||
|
||||
// Ensure that French language has a weight of 1 after being created through
|
||||
// the UI.
|
||||
|
@ -132,9 +132,9 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
$arabic->setWeight(4)->save();
|
||||
$this->assertEqual($arabic->getWeight(), 4, 'The Arabic language has a weight of 0.');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'de',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
|
||||
$language = $this->config('language.entity.de')->get();
|
||||
$this->assertEqual($language['langcode'], 'fr');
|
||||
|
@ -148,30 +148,30 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
/**
|
||||
* Functional tests for setting system language weight on adding, editing and deleting languages.
|
||||
*/
|
||||
function testLanguageConfigurationWeight() {
|
||||
public function testLanguageConfigurationWeight() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->checkConfigurableLanguageWeight();
|
||||
|
||||
// Add predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
|
||||
$this->checkConfigurableLanguageWeight('after adding new language');
|
||||
|
||||
// Re-ordering languages.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'languages[en][weight]' => $this->getHighestConfigurableLanguageWeight() + 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, 'Save configuration');
|
||||
$this->checkConfigurableLanguageWeight('after re-ordering');
|
||||
|
||||
// Remove predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'confirm' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/fr', $edit, 'Delete');
|
||||
$this->checkConfigurableLanguageWeight('after deleting a language');
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ class LanguageConfigurationTest extends WebTestBase {
|
|||
// Reset language list.
|
||||
\Drupal::languageManager()->reset();
|
||||
$max_configurable_language_weight = $this->getHighestConfigurableLanguageWeight();
|
||||
$replacements = array('@event' => $state);
|
||||
$replacements = ['@event' => $state];
|
||||
foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $locked_language) {
|
||||
$replacements['%language'] = $locked_language->getName();
|
||||
$this->assertTrue($locked_language->getWeight() > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements));
|
||||
|
|
|
@ -18,7 +18,7 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Functional tests for adding, editing and deleting languages.
|
||||
|
@ -26,76 +26,76 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
|
|||
public function testLanguageConfiguration() {
|
||||
|
||||
// Create user with permissions to add and remove languages.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add custom language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
);
|
||||
];
|
||||
$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.', ['@name' => t('Language code')]));
|
||||
$this->assertText(t('@name field is required.', ['@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.');
|
||||
$this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
||||
// Test validation of invalid values.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'white space',
|
||||
'label' => '<strong>evil markup</strong>',
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$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>.', [
|
||||
'%field' => t('Language code'),
|
||||
':url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
]));
|
||||
|
||||
$this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name'))));
|
||||
$this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
$this->assertRaw(t('%field cannot contain any markup.', ['%field' => t('Language name')]));
|
||||
$this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
||||
// Test adding a custom language with a numeric region code.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'es-419',
|
||||
'label' => 'Latin American Spanish',
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertRaw(t(
|
||||
'The language %language has been created and can now be used.',
|
||||
array('%language' => $edit['label'])
|
||||
['%language' => $edit['label']]
|
||||
));
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
||||
// Test validation of existing language values.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'de',
|
||||
'label' => 'German',
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
|
||||
// Add the language the first time.
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertRaw(t(
|
||||
'The language %language has been created and can now be used.',
|
||||
array('%language' => $edit['label'])
|
||||
['%language' => $edit['label']]
|
||||
));
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
||||
// Add the language a second time and confirm that this is not allowed.
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertRaw(t(
|
||||
'The language %language (%langcode) already exists.',
|
||||
array('%language' => $edit['label'], '%langcode' => $edit['langcode'])
|
||||
['%language' => $edit['label'], '%langcode' => $edit['langcode']]
|
||||
));
|
||||
$this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
$this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests enabling Language if a module exists that calls
|
||||
* LanguageManager::getLanguages() during installation.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageListModuleInstallTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language_test');
|
||||
|
||||
/**
|
||||
* Tests enabling Language.
|
||||
*/
|
||||
function testModuleInstallLanguageList() {
|
||||
// Since LanguageManager::getLanguages() uses static caches we need to do
|
||||
// this by enabling the module using the UI.
|
||||
$admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array();
|
||||
$edit['modules[Multilingual][language][enable]'] = 'language';
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
$this->assertEqual(\Drupal::state()->get('language_test.language_count_preinstall', 0), 1, 'Using LanguageManager::getLanguages() returns 1 language during Language installation.');
|
||||
|
||||
// Get updated module list by rebuilding container.
|
||||
$this->rebuildContainer();
|
||||
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('language'), 'Language module is enabled');
|
||||
}
|
||||
|
||||
}
|
|
@ -19,15 +19,15 @@ class LanguageListTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Functional tests for adding, editing and deleting languages.
|
||||
*/
|
||||
function testLanguageList() {
|
||||
public function testLanguageList() {
|
||||
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Get the weight of the last language.
|
||||
|
@ -35,9 +35,9 @@ class LanguageListTest extends WebTestBase {
|
|||
$last_language_weight = end($languages)->getWeight();
|
||||
|
||||
// Add predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
$this->assertText('French', 'Language added successfully.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
|
||||
|
@ -53,12 +53,12 @@ class LanguageListTest extends WebTestBase {
|
|||
// Add custom language.
|
||||
$langcode = 'xx';
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => Language::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
|
||||
$this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');
|
||||
|
@ -72,9 +72,9 @@ class LanguageListTest extends WebTestBase {
|
|||
$this->drupalGet($path);
|
||||
$this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.');
|
||||
// Change the default language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => $langcode,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.');
|
||||
|
@ -90,17 +90,17 @@ class LanguageListTest extends WebTestBase {
|
|||
$this->assertTitle(t('Edit language | Drupal'), 'Page title is "Edit language".');
|
||||
// Edit a language.
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'label' => $name,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language'));
|
||||
$this->assertRaw($name, 'The language has been updated.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language]));
|
||||
|
||||
// Change back the default language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => 'en',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save configuration'));
|
||||
$this->rebuildContainer();
|
||||
// Ensure 'delete' link works.
|
||||
|
@ -115,9 +115,9 @@ class LanguageListTest extends WebTestBase {
|
|||
$this->assertRaw($name, 'The language was not deleted.');
|
||||
// Delete the language for real. This a confirm form, we do not need any
|
||||
// fields changed.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/' . $langcode, array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/' . $langcode, [], t('Delete'));
|
||||
// We need raw here because %language and %langcode will add HTML.
|
||||
$t_args = array('%language' => $name, '%langcode' => $langcode);
|
||||
$t_args = ['%language' => $name, '%langcode' => $langcode];
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $english]));
|
||||
// Verify that language is no longer found.
|
||||
|
@ -125,11 +125,11 @@ class LanguageListTest extends WebTestBase {
|
|||
$this->assertResponse(404, 'Language no longer found.');
|
||||
|
||||
// Delete French.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/fr', [], t('Delete'));
|
||||
// Make sure the "language_count" state has been updated correctly.
|
||||
$this->rebuildContainer();
|
||||
// We need raw here because %language and %langcode will add HTML.
|
||||
$t_args = array('%language' => 'French', '%langcode' => 'fr');
|
||||
$t_args = ['%language' => 'French', '%langcode' => 'fr'];
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The French language has been removed.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
|
||||
// Verify that language is no longer found.
|
||||
|
@ -142,12 +142,12 @@ class LanguageListTest extends WebTestBase {
|
|||
// deleting English.
|
||||
$langcode = 'xx';
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => Language::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
|
||||
$this->assertText($name, 'Name found.');
|
||||
|
@ -157,17 +157,17 @@ class LanguageListTest extends WebTestBase {
|
|||
$this->drupalGet($path);
|
||||
$this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.');
|
||||
// Change the default language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => $langcode,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language]));
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
|
||||
// We need raw here because %language and %langcode will add HTML.
|
||||
$t_args = array('%language' => 'English', '%langcode' => 'en');
|
||||
$t_args = ['%language' => 'English', '%langcode' => 'en'];
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The English language has been removed.');
|
||||
$this->rebuildContainer();
|
||||
|
||||
|
@ -178,7 +178,7 @@ class LanguageListTest extends WebTestBase {
|
|||
// Ensure that NL cannot be set default when it's not available.
|
||||
$this->drupalGet('admin/config/regional/language');
|
||||
$extra_values = '&site_default_language=nl';
|
||||
$this->drupalPostForm(NULL, array(), t('Save configuration'), array(), array(), NULL, $extra_values);
|
||||
$this->drupalPostForm(NULL, [], t('Save configuration'), [], [], NULL, $extra_values);
|
||||
$this->assertText(t('Selected default language no longer exists.'));
|
||||
$this->assertNoFieldChecked('edit-site-default-language-xx', 'The previous default language got deselected.');
|
||||
}
|
||||
|
@ -186,24 +186,24 @@ class LanguageListTest extends WebTestBase {
|
|||
/**
|
||||
* Functional tests for the language states (locked or configurable).
|
||||
*/
|
||||
function testLanguageStates() {
|
||||
public function testLanguageStates() {
|
||||
// Add some languages, and also lock some of them.
|
||||
ConfigurableLanguage::create(array('label' => $this->randomMachineName(), 'id' => 'l1'))->save();
|
||||
ConfigurableLanguage::create(array('label' => $this->randomMachineName(), 'id' => 'l2', 'locked' => TRUE))->save();
|
||||
ConfigurableLanguage::create(array('label' => $this->randomMachineName(), 'id' => 'l3'))->save();
|
||||
ConfigurableLanguage::create(array('label' => $this->randomMachineName(), 'id' => 'l4', 'locked' => TRUE))->save();
|
||||
$expected_locked_languages = array('l4' => 'l4', 'l2' => 'l2', 'und' => 'und', 'zxx' => 'zxx');
|
||||
$expected_all_languages = array('l4' => 'l4', 'l3' => 'l3', 'l2' => 'l2', 'l1' => 'l1', 'en' => 'en', 'und' => 'und', 'zxx' => 'zxx');
|
||||
$expected_conf_languages = array('l3' => 'l3', 'l1' => 'l1', 'en' => 'en');
|
||||
ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l1'])->save();
|
||||
ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l2', 'locked' => TRUE])->save();
|
||||
ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l3'])->save();
|
||||
ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l4', 'locked' => TRUE])->save();
|
||||
$expected_locked_languages = ['l4' => 'l4', 'l2' => 'l2', 'und' => 'und', 'zxx' => 'zxx'];
|
||||
$expected_all_languages = ['l4' => 'l4', 'l3' => 'l3', 'l2' => 'l2', 'l1' => 'l1', 'en' => 'en', 'und' => 'und', 'zxx' => 'zxx'];
|
||||
$expected_conf_languages = ['l3' => 'l3', 'l1' => 'l1', 'en' => 'en'];
|
||||
|
||||
$locked_languages = $this->container->get('language_manager')->getLanguages(LanguageInterface::STATE_LOCKED);
|
||||
$this->assertEqual(array_diff_key($expected_locked_languages, $locked_languages), array(), 'Locked languages loaded correctly.');
|
||||
$this->assertEqual(array_diff_key($expected_locked_languages, $locked_languages), [], 'Locked languages loaded correctly.');
|
||||
|
||||
$all_languages = $this->container->get('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
|
||||
$this->assertEqual(array_diff_key($expected_all_languages, $all_languages), array(), 'All languages loaded correctly.');
|
||||
$this->assertEqual(array_diff_key($expected_all_languages, $all_languages), [], 'All languages loaded correctly.');
|
||||
|
||||
$conf_languages = $this->container->get('language_manager')->getLanguages();
|
||||
$this->assertEqual(array_diff_key($expected_conf_languages, $conf_languages), array(), 'Configurable languages loaded correctly.');
|
||||
$this->assertEqual(array_diff_key($expected_conf_languages, $conf_languages), [], 'Configurable languages loaded correctly.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class LanguageLocaleListTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'locale');
|
||||
public static $modules = ['language', 'locale'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -30,30 +30,30 @@ class LanguageLocaleListTest extends WebTestBase {
|
|||
/**
|
||||
* Tests adding, editing, and deleting languages.
|
||||
*/
|
||||
function testLanguageLocaleList() {
|
||||
public function testLanguageLocaleList() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
$this->assertText('The language French has been created and can now be used');
|
||||
$this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Translate Spanish language to French (Espagnol).
|
||||
$source = $this->storage->createString(array(
|
||||
$source = $this->storage->createString([
|
||||
'source' => 'Spanish',
|
||||
'context' => '',
|
||||
))->save();
|
||||
$this->storage->createTranslation(array(
|
||||
])->save();
|
||||
$this->storage->createTranslation([
|
||||
'lid' => $source->lid,
|
||||
'language' => 'fr',
|
||||
'translation' => 'Espagnol',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
// Get language list displayed in select list.
|
||||
$this->drupalGet('fr/admin/config/regional/language/add');
|
||||
|
|
|
@ -1,177 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests language negotiation with the language negotiator content entity.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationContentEntityTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'language_test', 'entity_test', 'system');
|
||||
|
||||
/**
|
||||
* The entity being used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ConfigurableLanguage::create(['id' => 'es'])->save();
|
||||
ConfigurableLanguage::create(['id' => 'fr'])->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
$this->createTranslatableEntity();
|
||||
|
||||
$user = $this->drupalCreateUser(array('view test entity'));
|
||||
$this->drupalLogin($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests default with content language remaining same as interface language.
|
||||
*/
|
||||
public function testDefaultConfiguration() {
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests enabling the language negotiator language_content_entity.
|
||||
*/
|
||||
public function testEnabledLanguageContentNegotiator() {
|
||||
// Define the method language-url with a higher priority than
|
||||
// language-content-entity. This configuration should match the default one,
|
||||
// where the language-content-entity is turned off.
|
||||
$config = $this->config('language.types');
|
||||
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationUrl::METHOD_ID => 0,
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The tests for the default configuration should still pass.
|
||||
$this->testDefaultConfiguration();
|
||||
|
||||
// Define the method language-content-entity with a higher priority than
|
||||
// language-url.
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 0,
|
||||
LanguageNegotiationUrl::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The method language-content-entity should run before language-url and
|
||||
// append query parameter for the content language and prevent language-url
|
||||
// from overwriting the URL.
|
||||
$default_site_langcode = $this->config('system.site')->get('default_langcode');
|
||||
|
||||
// Now switching to an entity route, so that the URL links are generated
|
||||
// while being on an entity route.
|
||||
$this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
|
||||
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $default_site_langcode) && ($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), 'Interface language and Content language are the same as the default translation language of the entity.');
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translated entity.
|
||||
*/
|
||||
protected function createTranslatableEntity() {
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->addTranslation('es', ['name' => 'name spanish']);
|
||||
$this->entity->addTranslation('fr', ['name' => 'name french']);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current request to a specific path with the corresponding route.
|
||||
*
|
||||
* @param string $path
|
||||
* The path for which the current request should be created.
|
||||
* @param string $route_name
|
||||
* The route name for which the route object for the request should be
|
||||
* created.
|
||||
*/
|
||||
protected function setCurrentRequestForRoute($path, $route_name) {
|
||||
$request = Request::create($path);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path));
|
||||
$this->container->get('request_stack')->push($request);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationInfoTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'view the administration theme', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'it'), t('Add language'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configurable language manager.
|
||||
*
|
||||
* @return \Drupal\language\ConfigurableLanguageManager
|
||||
*/
|
||||
protected function languageManager() {
|
||||
return $this->container->get('language_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state flags for language_test module.
|
||||
*
|
||||
* Ensures to correctly update data both in the child site and the test runner
|
||||
* environment.
|
||||
*
|
||||
* @param array $values
|
||||
* The key/value pairs to set in state.
|
||||
*/
|
||||
protected function stateSet(array $values) {
|
||||
// Set the new state values.
|
||||
$this->container->get('state')->setMultiple($values);
|
||||
// Refresh in-memory static state/config caches and static variables.
|
||||
$this->refreshVariables();
|
||||
// Refresh/rewrite language negotiation configuration, in order to pick up
|
||||
// the manipulations performed by language_test module's info alter hooks.
|
||||
$this->container->get('language_negotiator')->purgeConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*/
|
||||
function testInfoAlterations() {
|
||||
$this->stateSet(array(
|
||||
// Enable language_test type info.
|
||||
'language_test.language_types' => TRUE,
|
||||
// Enable language_test negotiation info (not altered yet).
|
||||
'language_test.language_negotiation_info' => TRUE,
|
||||
// Alter LanguageInterface::TYPE_CONTENT to be configurable.
|
||||
'language_test.content_language_type' => TRUE,
|
||||
));
|
||||
$this->container->get('module_installer')->install(array('language_test'));
|
||||
$this->resetAll();
|
||||
|
||||
// Check that fixed language types are properly configured without the need
|
||||
// of saving the language negotiation settings.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
$type = LanguageInterface::TYPE_CONTENT;
|
||||
$language_types = $this->languageManager()->getLanguageTypes();
|
||||
$this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');
|
||||
|
||||
// Enable some core and custom language negotiation methods. The test
|
||||
// language type is supposed to be configurable.
|
||||
$test_type = 'test_language_type';
|
||||
$interface_method_id = LanguageNegotiationUI::METHOD_ID;
|
||||
$test_method_id = 'test_language_negotiation_method';
|
||||
$form_field = $type . '[enabled][' . $interface_method_id . ']';
|
||||
$edit = array(
|
||||
$form_field => TRUE,
|
||||
$type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[configurable]' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Alter language negotiation info to remove interface language negotiation
|
||||
// method.
|
||||
$this->stateSet(array(
|
||||
'language_test.language_negotiation_info_alter' => TRUE,
|
||||
));
|
||||
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.');
|
||||
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertNoFieldByName($form_field, NULL, 'Interface language negotiation method unavailable.');
|
||||
|
||||
// Check that type-specific language negotiation methods can be assigned
|
||||
// only to the corresponding language types.
|
||||
foreach ($this->languageManager()->getLanguageTypes() as $type) {
|
||||
$form_field = $type . '[enabled][test_language_negotiation_method_ts]';
|
||||
if ($type == $test_type) {
|
||||
$this->assertFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method available for %type.', array('%type' => $type)));
|
||||
}
|
||||
else {
|
||||
$this->assertNoFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method unavailable for %type.', array('%type' => $type)));
|
||||
}
|
||||
}
|
||||
|
||||
// Check language negotiation results.
|
||||
$this->drupalGet('');
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$langcode = $last[$type];
|
||||
$value = $type == LanguageInterface::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
|
||||
$this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type, '%language' => $value)));
|
||||
}
|
||||
|
||||
// Uninstall language_test and check that everything is set back to the
|
||||
// original status.
|
||||
$this->container->get('module_installer')->uninstall(array('language_test'));
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Check that only the core language types are available.
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$this->assertTrue(strpos($type, 'test') === FALSE, format_string('The %type language is still available', array('%type' => $type)));
|
||||
}
|
||||
|
||||
// Check that fixed language types are properly configured, even those
|
||||
// previously set to configurable.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
// Check that unavailable language negotiation methods are not present in
|
||||
// the negotiation settings.
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$test_method_id]), 'The disabled test language negotiation method is not part of the content language negotiation settings.');
|
||||
|
||||
// Check that configuration page presents the correct options and settings.
|
||||
$this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
|
||||
$this->assertNoRaw(t('This is a test language negotiation method'), 'No test language negotiation method available.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that language negotiation for fixed types matches the stored one.
|
||||
*/
|
||||
protected function checkFixedLanguageTypes() {
|
||||
$configurable = $this->languageManager()->getLanguageTypes();
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
|
||||
if (!in_array($type, $configurable) && isset($info['fixed'])) {
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$equal = count($info['fixed']) == count($negotiation);
|
||||
while ($equal && list($id) = each($negotiation)) {
|
||||
list(, $info_id) = each($info['fixed']);
|
||||
$equal = $info_id == $id;
|
||||
}
|
||||
$this->assertTrue($equal, format_string('language negotiation for %type is properly set up', array('%type' => $type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests altering config of configurable language types.
|
||||
*/
|
||||
public function testConfigLangTypeAlterations() {
|
||||
// Default of config.
|
||||
$test_type = LanguageInterface::TYPE_CONTENT;
|
||||
$this->assertFalse($this->isLanguageTypeConfigurable($test_type), 'Language type is not configurable.');
|
||||
|
||||
// Editing config.
|
||||
$edit = [$test_type . '[configurable]' => TRUE];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is now configurable.');
|
||||
|
||||
// After installing another module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules', ['modules[Testing][test_module][enable]' => 1], t('Install'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
|
||||
// After uninstalling the other module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules/uninstall', ['uninstall[test_module]' => 1], t('Uninstall'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given language type is configurable.
|
||||
*
|
||||
* @param string $type
|
||||
* The language type.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the specified language type is configurable, FALSE otherwise.
|
||||
*/
|
||||
protected function isLanguageTypeConfigurable($type) {
|
||||
$configurable_types = $this->config('language.types')->get('configurable');
|
||||
return in_array($type, $configurable_types);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Confirm that paths are not changed on monolingual non-English sites.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguagePathMonolingualTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'language', 'path'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$web_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration'));
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Enable French language.
|
||||
$edit = array();
|
||||
$edit['predefined_langcode'] = 'fr';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Make French the default language.
|
||||
$edit = array(
|
||||
'site_default_language' => 'fr',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
|
||||
// Delete English.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
|
||||
|
||||
// Changing the default language causes a container rebuild. Therefore need
|
||||
// to rebuild the container in the test environment.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Verify that French is the only language.
|
||||
$this->container->get('language_manager')->reset();
|
||||
$this->assertFalse(\Drupal::languageManager()->isMultilingual(), 'Site is mono-lingual');
|
||||
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'fr', 'French is the default language');
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that links do not have language prefixes in them.
|
||||
*/
|
||||
function testPageLinks() {
|
||||
// Navigate to 'admin/config' path.
|
||||
$this->drupalGet('admin/config');
|
||||
|
||||
// Verify that links in this page do not have a 'fr/' prefix.
|
||||
$this->assertNoLinkByHref('/fr/', 'Links do not contain language prefix');
|
||||
|
||||
// Verify that links in this page can be followed and work.
|
||||
$this->clickLink(t('Languages'));
|
||||
$this->assertResponse(200, 'Clicked link results in a valid page');
|
||||
$this->assertText(t('Add language'), 'Page contains the add language text');
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
public static $modules = [
|
||||
'language',
|
||||
'content_translation',
|
||||
'node',
|
||||
|
@ -24,7 +24,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
|
|||
'field_ui',
|
||||
'entity_test',
|
||||
'locale',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The user with administrator privileges.
|
||||
|
@ -49,13 +49,13 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
|
|||
*/
|
||||
protected function getAdministratorPermissions() {
|
||||
return array_filter(
|
||||
array('translate interface',
|
||||
['translate interface',
|
||||
'administer content translation',
|
||||
'create content translations',
|
||||
'update content translations',
|
||||
'delete content translations',
|
||||
'administer languages',
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
|
|||
*/
|
||||
public function testLanguageStringSelector() {
|
||||
// Add another language.
|
||||
$edit = array('predefined_langcode' => 'es');
|
||||
$edit = ['predefined_langcode' => 'es'];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Translate the string English in Spanish (Inglés). Override config entity.
|
||||
|
@ -79,7 +79,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
|
|||
$this->drupalGet($path);
|
||||
|
||||
// Get en language from selector.
|
||||
$elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en'));
|
||||
$elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en']);
|
||||
|
||||
// Check that the language text is translated.
|
||||
$this->assertEqual((string) $elements[0], $name_translation, 'Checking the option string English is translated to Spanish.');
|
||||
|
|
|
@ -20,39 +20,39 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'locale_test', 'language', 'block', 'language_test', 'menu_ui');
|
||||
public static $modules = ['locale', 'locale_test', 'language', 'block', 'language_test', 'menu_ui'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks', 'administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Functional tests for the language switcher block.
|
||||
*/
|
||||
function testLanguageBlock() {
|
||||
public function testLanguageBlock() {
|
||||
// Add language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Set the native language name.
|
||||
$this->saveNativeLanguageName('fr', 'français');
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language_interface[enabled][language-url]' => '1');
|
||||
$edit = ['language_interface[enabled][language-url]' => '1'];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Enable the language switching block.
|
||||
$block = $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array(
|
||||
$block = $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
|
||||
'id' => 'test_language_block',
|
||||
// Ensure a 2-byte UTF-8 sequence is in the tested output.
|
||||
'label' => $this->randomMachineName(8) . '×',
|
||||
));
|
||||
]);
|
||||
|
||||
$this->doTestLanguageBlockAuthenticated($block->label());
|
||||
$this->doTestLanguageBlockAnonymous($block->label());
|
||||
|
@ -73,38 +73,38 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Assert that each list item and anchor element has the appropriate data-
|
||||
// attributes.
|
||||
list($language_switcher) = $this->xpath('//div[@id=:id]', array(':id' => 'block-test-language-block'));
|
||||
$list_items = array();
|
||||
$anchors = array();
|
||||
$labels = array();
|
||||
list($language_switcher) = $this->xpath('//div[@id=:id]', [':id' => 'block-test-language-block']);
|
||||
$list_items = [];
|
||||
$anchors = [];
|
||||
$labels = [];
|
||||
foreach ($language_switcher->ul->li as $list_item) {
|
||||
$classes = explode(" ", (string) $list_item['class']);
|
||||
list($langcode) = array_intersect($classes, array('en', 'fr'));
|
||||
$list_items[] = array(
|
||||
list($langcode) = array_intersect($classes, ['en', 'fr']);
|
||||
$list_items[] = [
|
||||
'langcode_class' => $langcode,
|
||||
'data-drupal-link-system-path' => (string) $list_item['data-drupal-link-system-path'],
|
||||
);
|
||||
$anchors[] = array(
|
||||
];
|
||||
$anchors[] = [
|
||||
'hreflang' => (string) $list_item->a['hreflang'],
|
||||
'data-drupal-link-system-path' => (string) $list_item->a['data-drupal-link-system-path'],
|
||||
);
|
||||
];
|
||||
$labels[] = (string) $list_item->a;
|
||||
}
|
||||
$expected_list_items = array(
|
||||
0 => array('langcode_class' => 'en', 'data-drupal-link-system-path' => 'user/2'),
|
||||
1 => array('langcode_class' => 'fr', 'data-drupal-link-system-path' => 'user/2'),
|
||||
);
|
||||
$expected_list_items = [
|
||||
0 => ['langcode_class' => 'en', 'data-drupal-link-system-path' => 'user/2'],
|
||||
1 => ['langcode_class' => 'fr', 'data-drupal-link-system-path' => 'user/2'],
|
||||
];
|
||||
$this->assertIdentical($list_items, $expected_list_items, 'The list items have the correct attributes that will allow the drupal.active-link library to mark them as active.');
|
||||
$expected_anchors = array(
|
||||
0 => array('hreflang' => 'en', 'data-drupal-link-system-path' => 'user/2'),
|
||||
1 => array('hreflang' => 'fr', 'data-drupal-link-system-path' => 'user/2'),
|
||||
);
|
||||
$expected_anchors = [
|
||||
0 => ['hreflang' => 'en', 'data-drupal-link-system-path' => 'user/2'],
|
||||
1 => ['hreflang' => 'fr', 'data-drupal-link-system-path' => 'user/2'],
|
||||
];
|
||||
$this->assertIdentical($anchors, $expected_anchors, 'The anchors have the correct attributes that will allow the drupal.active-link library to mark them as active.');
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertIdentical($settings['path']['currentPath'], 'user/2', 'drupalSettings.path.currentPath is set correctly to allow drupal.active-link to mark the correct links as active.');
|
||||
$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.');
|
||||
$this->assertIdentical($labels, array('English', 'français'), 'The language links labels are in their own language on the language switcher block.');
|
||||
$this->assertIdentical($labels, ['English', 'français'], 'The language links labels are in their own language on the language switcher block.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,19 +124,19 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$this->assertText($block_label, 'Language switcher block found.');
|
||||
|
||||
// Assert that only the current language is marked as active.
|
||||
list($language_switcher) = $this->xpath('//div[@id=:id]', array(':id' => 'block-test-language-block'));
|
||||
$links = array(
|
||||
'active' => array(),
|
||||
'inactive' => array(),
|
||||
);
|
||||
$anchors = array(
|
||||
'active' => array(),
|
||||
'inactive' => array(),
|
||||
);
|
||||
$labels = array();
|
||||
list($language_switcher) = $this->xpath('//div[@id=:id]', [':id' => 'block-test-language-block']);
|
||||
$links = [
|
||||
'active' => [],
|
||||
'inactive' => [],
|
||||
];
|
||||
$anchors = [
|
||||
'active' => [],
|
||||
'inactive' => [],
|
||||
];
|
||||
$labels = [];
|
||||
foreach ($language_switcher->ul->li as $link) {
|
||||
$classes = explode(" ", (string) $link['class']);
|
||||
list($langcode) = array_intersect($classes, array('en', 'fr'));
|
||||
list($langcode) = array_intersect($classes, ['en', 'fr']);
|
||||
if (in_array('is-active', $classes)) {
|
||||
$links['active'][] = $langcode;
|
||||
}
|
||||
|
@ -152,15 +152,15 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
}
|
||||
$labels[] = (string) $link->a;
|
||||
}
|
||||
$this->assertIdentical($links, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language list item is marked as active on the language switcher block.');
|
||||
$this->assertIdentical($anchors, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language anchor is marked as active on the language switcher block.');
|
||||
$this->assertIdentical($labels, array('English', 'français'), 'The language links labels are in their own language on the language switcher block.');
|
||||
$this->assertIdentical($links, ['active' => ['en'], 'inactive' => ['fr']], 'Only the current language list item is marked as active on the language switcher block.');
|
||||
$this->assertIdentical($anchors, ['active' => ['en'], 'inactive' => ['fr']], 'Only the current language anchor is marked as active on the language switcher block.');
|
||||
$this->assertIdentical($labels, ['English', 'français'], 'The language links labels are in their own language on the language switcher block.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test language switcher links for domain based negotiation.
|
||||
*/
|
||||
function testLanguageBlockWithDomain() {
|
||||
public function testLanguageBlockWithDomain() {
|
||||
// Add the Italian language.
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
|
@ -171,31 +171,31 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
// Enable browser and URL language detection.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_interface[enabled][language-url]' => TRUE,
|
||||
'language_interface[weight][language-url]' => -10,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Do not allow blank domain.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domain[en]' => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The domain may not be left blank for English'), 'The form does not allow blank domains.');
|
||||
|
||||
// Change the domain for the Italian language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domain[en]' => \Drupal::request()->getHost(),
|
||||
'domain[it]' => 'it.example.com',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved'), 'Domain configuration is saved.');
|
||||
|
||||
// Enable the language switcher block.
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array('id' => 'test_language_block'));
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, ['id' => 'test_language_block']);
|
||||
|
||||
$this->drupalGet('');
|
||||
|
||||
|
@ -203,34 +203,34 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
$generator = $this->container->get('url_generator');
|
||||
|
||||
// Verify the English URL is correct
|
||||
list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
|
||||
list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', [
|
||||
':id' => 'block-test-language-block',
|
||||
':hreflang' => 'en',
|
||||
));
|
||||
$english_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['en']));
|
||||
]);
|
||||
$english_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['en']]);
|
||||
$this->assertEqual($english_url, (string) $english_link['href']);
|
||||
|
||||
// Verify the Italian URL is correct
|
||||
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array(
|
||||
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', [
|
||||
':id' => 'block-test-language-block',
|
||||
':hreflang' => 'it',
|
||||
));
|
||||
$italian_url = $generator->generateFromRoute('entity.user.canonical', array('user' => 2), array('language' => $languages['it']));
|
||||
]);
|
||||
$italian_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['it']]);
|
||||
$this->assertEqual($italian_url, (string) $italian_link['href']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test active class on links when switching languages.
|
||||
*/
|
||||
function testLanguageLinkActiveClass() {
|
||||
public function testLanguageLinkActiveClass() {
|
||||
// Add language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language_interface[enabled][language-url]' => '1');
|
||||
$edit = ['language_interface[enabled][language-url]' => '1'];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
$this->doTestLanguageLinkActiveClassAuthenticated();
|
||||
|
@ -240,27 +240,27 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
/**
|
||||
* Check the path-admin class, as same as on default language.
|
||||
*/
|
||||
function testLanguageBodyClass() {
|
||||
public function testLanguageBodyClass() {
|
||||
$searched_class = 'path-admin';
|
||||
|
||||
// Add language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language_interface[enabled][language-url]' => '1');
|
||||
$edit = ['language_interface[enabled][language-url]' => '1'];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Check if the default (English) admin/config page has the right class.
|
||||
$this->drupalGet('admin/config');
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', array(':class' => $searched_class));
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', [':class' => $searched_class]);
|
||||
$this->assertTrue(isset($class[0]), t('The path-admin class appears on default language.'));
|
||||
|
||||
// Check if the French admin/config page has the right class.
|
||||
$this->drupalGet('fr/admin/config');
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', array(':class' => $searched_class));
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', [':class' => $searched_class]);
|
||||
$this->assertTrue(isset($class[0]), t('The path-admin class same as on default language.'));
|
||||
|
||||
// The testing profile sets the user/login page as the frontpage. That
|
||||
|
@ -270,12 +270,12 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Check if the default (English) frontpage has the right class.
|
||||
$this->drupalGet('<front>');
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', array(':class' => 'path-frontpage'));
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', [':class' => 'path-frontpage']);
|
||||
$this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag');
|
||||
|
||||
// Check if the French frontpage has the right class.
|
||||
$this->drupalGet('fr');
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', array(':class' => 'path-frontpage'));
|
||||
$class = $this->xpath('//body[contains(@class, :class)]', [':class' => 'path-frontpage']);
|
||||
$this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag with french as the active language');
|
||||
|
||||
}
|
||||
|
@ -295,18 +295,18 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Language code 'none' link should be active.
|
||||
$langcode = 'none';
|
||||
$links = $this->xpath('//a[@id = :id and @data-drupal-link-system-path = :path]', array(':id' => 'no_lang_link', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @data-drupal-link-system-path = :path]', [':id' => 'no_lang_link', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'en' link should be active.
|
||||
$langcode = 'en';
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', array(':id' => 'en_link', ':lang' => 'en', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', [':id' => 'en_link', ':lang' => 'en', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'fr' link should not be active.
|
||||
$langcode = 'fr';
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', array(':id' => 'fr_link', ':lang' => 'fr', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to NOT mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', [':id' => 'fr_link', ':lang' => 'fr', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to NOT mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Verify that drupalSettings contains the correct values.
|
||||
$settings = $this->getDrupalSettings();
|
||||
|
@ -320,18 +320,18 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Language code 'none' link should be active.
|
||||
$langcode = 'none';
|
||||
$links = $this->xpath('//a[@id = :id and @data-drupal-link-system-path = :path]', array(':id' => 'no_lang_link', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @data-drupal-link-system-path = :path]', [':id' => 'no_lang_link', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'en' link should not be active.
|
||||
$langcode = 'en';
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', array(':id' => 'en_link', ':lang' => 'en', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to NOT mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', [':id' => 'en_link', ':lang' => 'en', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to NOT mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'fr' link should be active.
|
||||
$langcode = 'fr';
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', array(':id' => 'fr_link', ':lang' => 'fr', ':path' => $path));
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and @hreflang = :lang and @data-drupal-link-system-path = :path]', [':id' => 'fr_link', ':lang' => 'fr', ':path' => $path]);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode has the correct attributes that will allow the drupal.active-link library to mark it as active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Verify that drupalSettings contains the correct values.
|
||||
$settings = $this->getDrupalSettings();
|
||||
|
@ -356,18 +356,18 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Language code 'none' link should be active.
|
||||
$langcode = 'none';
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'no_lang_link', ':class' => 'is-active'));
|
||||
$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)));
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [':id' => 'no_lang_link', ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'en' link should be active.
|
||||
$langcode = 'en';
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'en_link', ':class' => 'is-active'));
|
||||
$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)));
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [':id' => 'en_link', ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'fr' link should not be active.
|
||||
$langcode = 'fr';
|
||||
$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)));
|
||||
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', [':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.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Test links generated by the link generator on a French page.
|
||||
$current_language = 'French';
|
||||
|
@ -375,18 +375,18 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
|
||||
// Language code 'none' link should be active.
|
||||
$langcode = 'none';
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'no_lang_link', ':class' => 'is-active'));
|
||||
$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)));
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [':id' => 'no_lang_link', ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'en' link should not be active.
|
||||
$langcode = 'en';
|
||||
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', array(':id' => 'en_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)));
|
||||
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', [':id' => 'en_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.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
|
||||
// Language code 'fr' link should be active.
|
||||
$langcode = 'fr';
|
||||
$links = $this->xpath('//a[@id = :id and 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 marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
|
||||
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [':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 marked active.', [':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,27 +394,27 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
*/
|
||||
public function testLanguageSessionSwitchLinks() {
|
||||
// Add language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Enable session language detection and selection.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'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(
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
|
||||
'id' => 'test_language_block',
|
||||
));
|
||||
]);
|
||||
|
||||
// Enable the main menu block.
|
||||
$this->drupalPlaceBlock('system_menu_block:main', array(
|
||||
$this->drupalPlaceBlock('system_menu_block:main', [
|
||||
'id' => 'test_menu',
|
||||
));
|
||||
]);
|
||||
|
||||
// Add a link to the homepage.
|
||||
$link = MenuLinkContent::create([
|
||||
|
|
|
@ -30,7 +30,7 @@ class LanguageTourTest extends TourTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'access tour'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'access tour']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
|
|
@ -48,19 +48,19 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'language_test', 'block', 'user', 'content_translation');
|
||||
public static $modules = ['locale', 'language_test', 'block', 'user', 'content_translation'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages', 'administer blocks']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for language switching by URL path.
|
||||
*/
|
||||
function testUILanguageNegotiation() {
|
||||
public function testUILanguageNegotiation() {
|
||||
// A few languages to switch to.
|
||||
// This one is unknown, should get the default lang version.
|
||||
$langcode_unknown = 'blah-blah';
|
||||
|
@ -69,9 +69,9 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
// For testing path prefix.
|
||||
$langcode = 'zh-hans';
|
||||
// For setting browser language preference to 'vi'.
|
||||
$http_header_browser_fallback = array("Accept-Language: $langcode_browser_fallback;q=1");
|
||||
$http_header_browser_fallback = ["Accept-Language: $langcode_browser_fallback;q=1"];
|
||||
// For setting browser language preference to some unknown.
|
||||
$http_header_blah = array("Accept-Language: blah;q=1");
|
||||
$http_header_blah = ["Accept-Language: blah;q=1"];
|
||||
|
||||
// Setup the site languages by installing two languages.
|
||||
// Set the default language in order for the translated string to be registered
|
||||
|
@ -101,117 +101,117 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$language_browser_fallback_string = "In $langcode_browser_fallback In $langcode_browser_fallback In $langcode_browser_fallback";
|
||||
$language_string = "In $langcode In $langcode In $langcode";
|
||||
// Do a translate search of our target string.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $default_string,
|
||||
'langcode' => $langcode_browser_fallback,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $language_browser_fallback_string,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $default_string,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $language_string,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Configure selected language negotiation to use zh-hans.
|
||||
$edit = array('selected_langcode' => $langcode);
|
||||
$edit = ['selected_langcode' => $langcode];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/selected', $edit, t('Save configuration'));
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationSelected::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'SELECTED: UI language is switched based on selected language.',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// An invalid language is selected.
|
||||
$this->config('language.negotiation')->set('selected_langcode', NULL)->save();
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// No selected language is available.
|
||||
$this->config('language.negotiation')->set('selected_langcode', $langcode_unknown)->save();
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
$tests = array(
|
||||
$tests = [
|
||||
// Default, browser preference should have no influence.
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
|
||||
),
|
||||
],
|
||||
// Language prefix.
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => "$langcode/admin/config",
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationUrl::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
|
||||
),
|
||||
],
|
||||
// Default, go by browser preference.
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID),
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $language_browser_fallback_string,
|
||||
'expected_method_id' => LanguageNegotiationBrowser::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
|
||||
),
|
||||
],
|
||||
// Prefix, switch to the language.
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID),
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID],
|
||||
'path' => "$langcode/admin/config",
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationUrl::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'URL (PATH) > BROWSER: with language prefix, UI language is based on path prefix',
|
||||
),
|
||||
],
|
||||
// Default, browser language preference is not one of site's lang.
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => $http_header_blah,
|
||||
'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($tests as $test) {
|
||||
$this->runTest($test);
|
||||
$this->doRunTest($test);
|
||||
}
|
||||
|
||||
// Unknown language prefix should return 404.
|
||||
|
@ -224,7 +224,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$this->config('language.types')
|
||||
->set('negotiation.' . LanguageInterface::TYPE_INTERFACE . '.enabled', array_flip(array_keys($language_interface_method_definitions)))
|
||||
->save();
|
||||
$this->drupalGet("$langcode_unknown/admin/config", array(), $http_header_browser_fallback);
|
||||
$this->drupalGet("$langcode_unknown/admin/config", [], $http_header_browser_fallback);
|
||||
$this->assertResponse(404, "Unknown language path prefix should return 404");
|
||||
|
||||
// Set preferred langcode for user to NULL.
|
||||
|
@ -232,117 +232,117 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$account->preferred_langcode = NULL;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER > DEFAULT: no preferred user language setting, the UI language is default',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Set preferred langcode for user to unknown language.
|
||||
$account = $this->loggedInUser;
|
||||
$account->preferred_langcode = $langcode_unknown;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER > DEFAULT: invalid preferred user language setting, the UI language is default',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Set preferred langcode for user to non default.
|
||||
$account->preferred_langcode = $langcode;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationUser::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER > DEFAULT: defined preferred user language setting, the UI language is based on user setting',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Set preferred admin langcode for user to NULL.
|
||||
$account->preferred_admin_langcode = NULL;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER ADMIN > DEFAULT: no preferred user admin language setting, the UI language is default',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Set preferred admin langcode for user to unknown language.
|
||||
$account->preferred_admin_langcode = $langcode_unknown;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER ADMIN > DEFAULT: invalid preferred user admin language setting, the UI language is default',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Set preferred admin langcode for user to non default.
|
||||
$account->preferred_admin_langcode = $langcode;
|
||||
$account->save();
|
||||
|
||||
$test = array(
|
||||
'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
|
||||
$test = [
|
||||
'language_negotiation' => [LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationUserAdmin::METHOD_ID,
|
||||
'http_header' => array(),
|
||||
'http_header' => [],
|
||||
'message' => 'USER ADMIN > DEFAULT: defined preferred user admin language setting, the UI language is based on user setting',
|
||||
);
|
||||
$this->runTest($test);
|
||||
];
|
||||
$this->doRunTest($test);
|
||||
|
||||
// Go by session preference.
|
||||
$language_negotiation_session_param = $this->randomMachineName();
|
||||
$edit = array('language_negotiation_session_param' => $language_negotiation_session_param);
|
||||
$edit = ['language_negotiation_session_param' => $language_negotiation_session_param];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/session', $edit, t('Save configuration'));
|
||||
$tests = array(
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationSession::METHOD_ID),
|
||||
$tests = [
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationSession::METHOD_ID],
|
||||
'path' => "admin/config",
|
||||
'expect' => $default_string,
|
||||
'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'SESSION > DEFAULT: no language given, the UI language is default',
|
||||
),
|
||||
array(
|
||||
'language_negotiation' => array(LanguageNegotiationSession::METHOD_ID),
|
||||
],
|
||||
[
|
||||
'language_negotiation' => [LanguageNegotiationSession::METHOD_ID],
|
||||
'path' => 'admin/config',
|
||||
'path_options' => ['query' => [$language_negotiation_session_param => $langcode]],
|
||||
'expect' => $language_string,
|
||||
'expected_method_id' => LanguageNegotiationSession::METHOD_ID,
|
||||
'http_header' => $http_header_browser_fallback,
|
||||
'message' => 'SESSION > DEFAULT: language given, UI language is determined by session language preference',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
foreach ($tests as $test) {
|
||||
$this->runTest($test);
|
||||
$this->doRunTest($test);
|
||||
}
|
||||
}
|
||||
|
||||
protected function runTest($test) {
|
||||
$test += array('path_options' => []);
|
||||
protected function doRunTest($test) {
|
||||
$test += ['path_options' => []];
|
||||
if (!empty($test['language_negotiation'])) {
|
||||
$method_weights = array_flip($test['language_negotiation']);
|
||||
$this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_INTERFACE, $method_weights);
|
||||
|
@ -358,13 +358,13 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$this->container->get('language_manager')->reset();
|
||||
$this->drupalGet($test['path'], $test['path_options'], $test['http_header']);
|
||||
$this->assertText($test['expect'], $test['message']);
|
||||
$this->assertText(t('Language negotiation method: @name', array('@name' => $test['expected_method_id'])));
|
||||
$this->assertText(t('Language negotiation method: @name', ['@name' => $test['expected_method_id']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test URL language detection when the requested URL has no language.
|
||||
*/
|
||||
function testUrlLanguageFallback() {
|
||||
public function testUrlLanguageFallback() {
|
||||
// Add the Italian language.
|
||||
$langcode_browser_fallback = 'it';
|
||||
ConfigurableLanguage::createFromLangcode($langcode_browser_fallback)->save();
|
||||
|
@ -372,21 +372,21 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
|
||||
// Enable the path prefix for the default language: this way any unprefixed
|
||||
// URL must have a valid fallback value.
|
||||
$edit = array('prefix[en]' => 'en');
|
||||
$edit = ['prefix[en]' => 'en'];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
|
||||
// Enable browser and URL language detection.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_interface[enabled][language-browser]' => TRUE,
|
||||
'language_interface[enabled][language-url]' => TRUE,
|
||||
'language_interface[weight][language-browser]' => -8,
|
||||
'language_interface[weight][language-url]' => -10,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
|
||||
// Enable the language switcher block.
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array('id' => 'test_language_block'));
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, ['id' => 'test_language_block']);
|
||||
|
||||
// Log out, because for anonymous users, the "active" class is set by PHP
|
||||
// (which means we can easily test it here), whereas for authenticated users
|
||||
|
@ -398,13 +398,13 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
|
||||
// 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");
|
||||
$language = new Language(array('id' => ''));
|
||||
$this->drupalGet('', array('language' => $language), $http_header);
|
||||
$http_header = ["Accept-Language: $langcode_browser_fallback;q=1"];
|
||||
$language = new Language(['id' => '']);
|
||||
$this->drupalGet('', ['language' => $language], $http_header);
|
||||
|
||||
// Check that the language switcher active link matches the given browser
|
||||
// language.
|
||||
$args = array(':id' => 'block-test-language-block', ':url' => \Drupal::url('<front>') . $langcode_browser_fallback);
|
||||
$args = [':id' => 'block-test-language-block', ':url' => \Drupal::url('<front>') . $langcode_browser_fallback];
|
||||
$fields = $this->xpath('//div[@id=:id]//a[@class="language-link is-active" and starts-with(@href, :url)]', $args);
|
||||
$this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
|
||||
|
||||
|
@ -416,7 +416,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
/**
|
||||
* Tests URL handling when separate domains are used for multiple languages.
|
||||
*/
|
||||
function testLanguageDomain() {
|
||||
public function testLanguageDomain() {
|
||||
global $base_url;
|
||||
|
||||
// Get the current host URI we're running on.
|
||||
|
@ -428,27 +428,27 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
// Enable browser and URL language detection.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_interface[enabled][language-url]' => TRUE,
|
||||
'language_interface[weight][language-url]' => -10,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Do not allow blank domain.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domain[en]' => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
$this->assertText('The domain may not be left blank for English', 'The form does not allow blank domains.');
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Change the domain for the Italian language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domain[en]' => $base_url_host,
|
||||
'domain[it]' => 'it.example.com',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
$this->assertText('The configuration options have been saved', 'Domain configuration is saved.');
|
||||
$this->rebuildContainer();
|
||||
|
@ -471,19 +471,19 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString();
|
||||
$url_scheme = \Drupal::request()->isSecure() ? 'https://' : 'http://';
|
||||
$correct_link = $url_scheme . $link;
|
||||
$this->assertEqual($italian_url, $correct_link, format_string('The right URL (@url) in accordance with the chosen language', array('@url' => $italian_url)));
|
||||
$this->assertEqual($italian_url, $correct_link, format_string('The right URL (@url) in accordance with the chosen language', ['@url' => $italian_url]));
|
||||
|
||||
// Test HTTPS via options.
|
||||
$italian_url = Url::fromRoute('system.admin', [], ['https' => TRUE, 'language' => $languages['it']])->toString();
|
||||
$correct_link = 'https://' . $link;
|
||||
$this->assertTrue($italian_url == $correct_link, format_string('The right HTTPS URL (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url)));
|
||||
$this->assertTrue($italian_url == $correct_link, format_string('The right HTTPS URL (via options) (@url) in accordance with the chosen language', ['@url' => $italian_url]));
|
||||
|
||||
// Test HTTPS via current URL scheme.
|
||||
$request = Request::create('', 'GET', array(), array(), array(), array('HTTPS' => 'on'));
|
||||
$request = Request::create('', 'GET', [], [], [], ['HTTPS' => 'on']);
|
||||
$this->container->get('request_stack')->push($request);
|
||||
$italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString();
|
||||
$correct_link = 'https://' . $link;
|
||||
$this->assertTrue($italian_url == $correct_link, format_string('The right URL (via current URL scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url)));
|
||||
$this->assertTrue($italian_url == $correct_link, format_string('The right URL (via current URL scheme) (@url) in accordance with the chosen language', ['@url' => $italian_url]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,11 +491,11 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
*/
|
||||
public function testContentCustomization() {
|
||||
// Customize content language settings from their defaults.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_content[configurable]' => TRUE,
|
||||
'language_content[enabled][language-url]' => FALSE,
|
||||
'language_content[enabled][language-session]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Check if configurability persisted.
|
||||
|
@ -515,16 +515,16 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
|
|||
$block_id = 'test_language_block';
|
||||
|
||||
// Enable the language switcher block.
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_CONTENT, array('id' => $block_id));
|
||||
$this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_CONTENT, ['id' => $block_id]);
|
||||
|
||||
// Check if the language switcher block has been created.
|
||||
$block = Block::load($block_id);
|
||||
$this->assertTrue($block, 'Language switcher block was created.');
|
||||
|
||||
// Make sure language_content is not configurable.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_content[configurable]' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'language_test');
|
||||
public static $modules = ['language', 'language_test'];
|
||||
|
||||
/**
|
||||
* An user with permissions to administer languages.
|
||||
|
@ -34,16 +34,16 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$this->webUser = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$this->webUser = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
||||
// Install French language.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'fr';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language_interface[enabled][language-url]' => 1);
|
||||
$edit = ['language_interface[enabled][language-url]' => 1];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Check that drupalSettings contains path prefix.
|
||||
|
@ -54,9 +54,9 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
/**
|
||||
* Check that non-installed languages are not considered.
|
||||
*/
|
||||
function testUrlRewritingEdgeCases() {
|
||||
public function testUrlRewritingEdgeCases() {
|
||||
// Check URL rewriting with a non-installed language.
|
||||
$non_existing = new Language(array('id' => $this->randomMachineName()));
|
||||
$non_existing = new Language(['id' => $this->randomMachineName()]);
|
||||
$this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');
|
||||
|
||||
// Check that URL rewriting is not applied to subrequests.
|
||||
|
@ -79,9 +79,9 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
* The message to display confirming prefixed URL is not working.
|
||||
*/
|
||||
private function checkUrl(LanguageInterface $language, $message1, $message2) {
|
||||
$options = array('language' => $language, 'script' => '');
|
||||
$options = ['language' => $language, 'script' => ''];
|
||||
$base_path = trim(base_path(), '/');
|
||||
$rewritten_path = trim(str_replace($base_path, '', \Drupal::url('<front>', array(), $options)), '/');
|
||||
$rewritten_path = trim(str_replace($base_path, '', \Drupal::url('<front>', [], $options)), '/');
|
||||
$segments = explode('/', $rewritten_path, 2);
|
||||
$prefix = $segments[0];
|
||||
$path = isset($segments[1]) ? $segments[1] : $prefix;
|
||||
|
@ -101,16 +101,16 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
/**
|
||||
* Check URL rewriting when using a domain name and a non-standard port.
|
||||
*/
|
||||
function testDomainNameNegotiationPort() {
|
||||
public function testDomainNameNegotiationPort() {
|
||||
global $base_url;
|
||||
$language_domain = 'example.fr';
|
||||
// Get the current host URI we're running on.
|
||||
$base_url_host = parse_url($base_url, PHP_URL_HOST);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domain[en]' => $base_url_host,
|
||||
'domain[fr]' => $language_domain
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
// Rebuild the container so that the new language gets picked up by services
|
||||
// that hold the list of languages.
|
||||
|
@ -126,11 +126,11 @@ class LanguageUrlRewritingTest extends WebTestBase {
|
|||
|
||||
// In case index.php is part of the URLs, we need to adapt the asserted
|
||||
// URLs as well.
|
||||
$index_php = strpos(\Drupal::url('<front>', array(), array('absolute' => TRUE)), 'index.php') !== FALSE;
|
||||
$index_php = strpos(\Drupal::url('<front>', [], ['absolute' => TRUE]), 'index.php') !== FALSE;
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$server = $request->server->all();
|
||||
$request = $this->prepareRequestForGenerator(TRUE, array('HTTP_HOST' => $server['HTTP_HOST'] . ':88'));
|
||||
$request = $this->prepareRequestForGenerator(TRUE, ['HTTP_HOST' => $server['HTTP_HOST'] . ':88']);
|
||||
|
||||
// Create an absolute French link.
|
||||
$language = \Drupal::languageManager()->getLanguage('fr');
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Tests\Migrate;
|
||||
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Asserts various properties of a configurable language entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The language ID.
|
||||
* @param string $label
|
||||
* The language name.
|
||||
* @param string $direction
|
||||
* (optional) The language's direction (one of the DIRECTION_* constants in
|
||||
* ConfigurableLanguageInterface). Defaults to LTR.
|
||||
* @param int $weight
|
||||
* (optional) The weight of the language. Defaults to 0.
|
||||
*/
|
||||
protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0) {
|
||||
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
|
||||
$language = ConfigurableLanguage::load($id);
|
||||
$this->assertTrue($language instanceof ConfigurableLanguageInterface);
|
||||
$this->assertIdentical($label, $language->label());
|
||||
$this->assertIdentical($direction, $language->getDirection());
|
||||
$this->assertIdentical(0, $language->getWeight());
|
||||
$this->assertFalse($language->isLocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of Drupal 6 languages to configurable language entities.
|
||||
*/
|
||||
public function testLanguageMigration() {
|
||||
$this->executeMigration('language');
|
||||
$this->assertLanguage('en', 'English');
|
||||
$this->assertLanguage('fr', 'French');
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue