Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -50,14 +50,14 @@ function hook_config_translation_info(&$info) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
$info[$entity_type_id . '_fields'] = [
'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
'entity_type' => 'field_config',
'title' => t('Title'),
'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id,
'weight' => 10,
);
];
}
}
}

View file

@ -5,6 +5,7 @@
* Configuration Translation module.
*/
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\FieldConfigInterface;
@ -17,15 +18,15 @@ function config_translation_help($route_name, RouteMatchInterface $route_match)
case 'help.page.config_translation':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href=":language">Language</a>, <a href=":content-translation">Content Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":doc_url">online documentation for the Configuration Translation module</a>.', array(':doc_url' => 'https://www.drupal.org/documentation/modules/config_translation', ':config' => \Drupal::url('help.page', array('name' => 'config')), ':language' => \Drupal::url('help.page', array('name' => 'language')), ':locale' => \Drupal::url('help.page', array('name' => 'locale')), ':content-translation' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#')) . '</p>';
$output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href=":language">Language</a>, <a href=":content-translation">Content Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":doc_url">online documentation for the Configuration Translation module</a>.', [':doc_url' => 'https://www.drupal.org/documentation/modules/config_translation', ':config' => \Drupal::url('help.page', ['name' => 'config']), ':language' => \Drupal::url('help.page', ['name' => 'language']), ':locale' => \Drupal::url('help.page', ['name' => 'locale']), ':content-translation' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', ['name' => 'content_translation']) : '#']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Enabling translation') . '</dt>';
$output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', array(':url' => \Drupal::url('entity.configurable_language.collection'))) . '</dd>';
$output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => \Drupal::url('entity.configurable_language.collection')]) . '</dd>';
$output .= '<dt>' . t('Translating configuration text') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href=":translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', array(':translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href=":translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', [':translation-page' => \Drupal::url('config_translation.mapper_list')]) . '</dd>';
$output .= '<dt>' . t('Translating date formats') . '</dt>';
$output .= '<dd>' . t('You can choose to translate date formats on the <a href=":translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', array(':translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
$output .= '<dd>' . t('You can choose to translate date formats on the <a href=":translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', [':translation-page' => \Drupal::url('config_translation.mapper_list')]) . '</dd>';
$output .= '</dl>';
return $output;
@ -39,12 +40,12 @@ function config_translation_help($route_name, RouteMatchInterface $route_match)
* Implements hook_theme().
*/
function config_translation_theme() {
return array(
'config_translation_manage_form_element' => array(
return [
'config_translation_manage_form_element' => [
'render element' => 'element',
'template' => 'config_translation_manage_form_element',
),
);
],
];
}
/**
@ -75,7 +76,7 @@ function config_translation_themes_uninstalled() {
function config_translation_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_types as $entity_type_id => $entity_type) {
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
if ($entity_type->entityClassImplements(ConfigEntityInterface::class)) {
if ($entity_type_id == 'block') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder';
}
@ -109,13 +110,13 @@ function config_translation_config_translation_info(&$info) {
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route')) {
$info[$entity_type_id . '_fields'] = array(
$info[$entity_type_id . '_fields'] = [
'base_route_name' => "entity.field_config.{$entity_type_id}_field_edit_form",
'entity_type' => 'field_config',
'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id,
'weight' => 10,
);
];
}
}
}
@ -125,7 +126,7 @@ function config_translation_config_translation_info(&$info) {
// Determine base path for entities automatically if provided via the
// configuration entity.
if (
!$entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') ||
!$entity_type->entityClassImplements(ConfigEntityInterface::class) ||
!$entity_type->hasLinkTemplate('edit-form')
) {
// Do not record this entity mapper if the entity type does not
@ -137,14 +138,14 @@ function config_translation_config_translation_info(&$info) {
// Use the entity type as the plugin ID.
$base_route_name = "entity.$entity_type_id.edit_form";
$info[$entity_type_id] = array(
$info[$entity_type_id] = [
'class' => '\Drupal\config_translation\ConfigEntityMapper',
'base_route_name' => $base_route_name,
'title' => $entity_type->getLowercaseLabel(),
'names' => array(),
'names' => [],
'entity_type' => $entity_type_id,
'weight' => 10,
);
];
}
}
@ -152,9 +153,9 @@ function config_translation_config_translation_info(&$info) {
* Implements hook_entity_operation().
*/
function config_translation_entity_operation(EntityInterface $entity) {
$operations = array();
$operations = [];
$entity_type = $entity->getEntityType();
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') &&
if ($entity_type->entityClassImplements(ConfigEntityInterface::class) &&
$entity->hasLinkTemplate('config-translation-overview') &&
\Drupal::currentUser()->hasPermission('translate configuration')) {
@ -163,11 +164,11 @@ function config_translation_entity_operation(EntityInterface $entity) {
$link_template = "config-translation-overview.{$entity->getTargetEntityTypeId()}";
}
$operations['translate'] = array(
$operations['translate'] = [
'title' => t('Translate'),
'weight' => 50,
'url' => $entity->urlInfo($link_template),
);
];
}
return $operations;
@ -177,7 +178,7 @@ function config_translation_entity_operation(EntityInterface $entity) {
* Implements hook_config_schema_info_alter().
*/
function config_translation_config_schema_info_alter(&$definitions) {
$map = array(
$map = [
'label' => '\Drupal\config_translation\FormElement\Textfield',
'text' => '\Drupal\config_translation\FormElement\Textarea',
'date_format' => '\Drupal\config_translation\FormElement\DateFormat',
@ -185,7 +186,7 @@ function config_translation_config_schema_info_alter(&$definitions) {
'mapping' => '\Drupal\config_translation\FormElement\ListElement',
'sequence' => '\Drupal\config_translation\FormElement\ListElement',
'plural_label' => '\Drupal\config_translation\FormElement\PluralVariants',
);
];
// Enhance the text and date type definitions with classes to generate proper
// form elements in ConfigTranslationFormBase. Other translatable types will

View file

@ -0,0 +1,29 @@
id: d6_i18n_user_profile_field_instance
label: User profile field instance configuration
migration_tags:
- Drupal 6
source:
plugin: d6_i18n_profile_field
constants:
entity_type: user
bundle: user
process:
langcode: language
entity_type: 'constants/entity_type'
bundle: 'constants/bundle'
field_name: name
property:
plugin: static_map
source: property
map:
title: label
options: options
explanation: description
translation: translation
destination:
plugin: entity:field_config
translations: true
migration_dependencies:
required:
- user_profile_field
- user_profile_field_instance

View file

@ -113,7 +113,7 @@ class ConfigEntityMapper extends ConfigNamesMapper {
/**
* Gets the entity instance for this mapper.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface
* The configuration entity.
*/
public function getEntity() {
@ -165,7 +165,7 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* {@inheritdoc}
*/
public function getBaseRouteParameters() {
return array($this->entityType => $this->entity->id());
return [$this->entityType => $this->entity->id()];
}
/**
@ -220,14 +220,14 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* {@inheritdoc}
*/
public function getOperations() {
return array(
'list' => array(
return [
'list' => [
'title' => $this->t('List'),
'url' => Url::fromRoute('config_translation.entity_list', [
'mapper_id' => $this->getPluginId(),
]),
),
);
],
];
}
/**
@ -259,12 +259,12 @@ class ConfigEntityMapper extends ConfigNamesMapper {
*/
protected function processRoute(Route $route) {
// Add entity upcasting information.
$parameters = $route->getOption('parameters') ?: array();
$parameters += array(
$this->entityType => array(
$parameters = $route->getOption('parameters') ?: [];
$parameters += [
$this->entityType => [
'type' => 'entity:' . $this->entityType,
)
);
]
];
$route->setOption('parameters', $parameters);
}

View file

@ -44,7 +44,7 @@ class ConfigFieldMapper extends ConfigEntityMapper {
*/
public function getTypeLabel() {
$base_entity_info = $this->entityManager->getDefinition($this->pluginDefinition['base_entity_type']);
return $this->t('@label fields', array('@label' => $base_entity_info->getLabel()));
return $this->t('@label fields', ['@label' => $base_entity_info->getLabel()]);
}
/**

View file

@ -39,12 +39,12 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
/**
* {@inheritdoc}
*/
protected $defaults = array(
protected $defaults = [
'title' => '',
'names' => array(),
'names' => [],
'weight' => 20,
'class' => '\Drupal\config_translation\ConfigNamesMapper',
);
];
/**
* Constructs a ConfigMapperManager.
@ -72,7 +72,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
$this->alterInfo('config_translation_info');
// Config translation only uses an info hook discovery, cache by language.
$cache_key = 'config_translation_info_plugins' . ':' . $language_manager->getCurrentLanguage()->getId();
$this->setCacheBackend($cache_backend, $cache_key, array('config_translation_info_plugins'));
$this->setCacheBackend($cache_backend, $cache_key, ['config_translation_info_plugins']);
}
/**
@ -90,7 +90,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
// request; when routes are being rebuilt at the end of the request,
// this service only happens to get instantiated with the updated list
// of installed themes.
$directories = array();
$directories = [];
foreach ($this->moduleHandler->getModuleList() as $name => $module) {
$directories[$name] = $module->getPath();
}
@ -111,7 +111,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
* {@inheritdoc}
*/
public function getMappers(RouteCollection $collection = NULL) {
$mappers = array();
$mappers = [];
foreach ($this->getDefinitions() as $id => $definition) {
$mappers[$id] = $this->createInstance($id);
if ($collection) {
@ -155,7 +155,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
// If this plugin was provided by a module that does not exist, remove the
// plugin definition.
foreach ($definitions as $plugin_id => $plugin_definition) {
if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('core', 'component')) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], ['core', 'component']) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
unset($definitions[$plugin_id]);
}
}

View file

@ -180,7 +180,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* {@inheritdoc}
*/
public function getBaseRouteParameters() {
return array();
return [];
}
/**
@ -231,11 +231,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
public function getOverviewRoute() {
$route = new Route(
$this->getBaseRoute()->getPath() . '/translate',
array(
[
'_controller' => '\Drupal\config_translation\Controller\ConfigTranslationController::itemPage',
'plugin_id' => $this->getPluginId(),
),
array('_config_translation_overview_access' => 'TRUE')
],
['_config_translation_overview_access' => 'TRUE']
);
$this->processRoute($route);
return $route;
@ -272,11 +272,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
public function getAddRoute() {
$route = new Route(
$this->getBaseRoute()->getPath() . '/translate/{langcode}/add',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationAddForm',
'plugin_id' => $this->getPluginId(),
),
array('_config_translation_form_access' => 'TRUE')
],
['_config_translation_form_access' => 'TRUE']
);
$this->processRoute($route);
return $route;
@ -302,11 +302,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
public function getEditRoute() {
$route = new Route(
$this->getBaseRoute()->getPath() . '/translate/{langcode}/edit',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationEditForm',
'plugin_id' => $this->getPluginId(),
),
array('_config_translation_form_access' => 'TRUE')
],
['_config_translation_form_access' => 'TRUE']
);
$this->processRoute($route);
return $route;
@ -332,11 +332,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
public function getDeleteRoute() {
$route = new Route(
$this->getBaseRoute()->getPath() . '/translate/{langcode}/delete',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationDeleteForm',
'plugin_id' => $this->getPluginId(),
),
array('_config_translation_form_access' => 'TRUE')
],
['_config_translation_form_access' => 'TRUE']
);
$this->processRoute($route);
return $route;
@ -413,7 +413,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* {@inheritdoc}
*/
public function getConfigData() {
$config_data = array();
$config_data = [];
foreach ($this->getConfigNames() as $name) {
$config_data[$name] = $this->configFactory->getEditable($name)->get();
}
@ -467,12 +467,12 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* {@inheritdoc}
*/
public function getOperations() {
return array(
'translate' => array(
return [
'translate' => [
'title' => $this->t('Translate'),
'url' => Url::fromRoute($this->getOverviewRouteName(), $this->getOverviewRouteParameters()),
),
);
],
];
}
/**

View file

@ -18,7 +18,7 @@ class ConfigTranslationBlockListBuilder extends ConfigTranslationEntityListBuild
*
* @var array
*/
protected $themes = array();
protected $themes = [];
/**
* {@inheritdoc}
@ -58,20 +58,20 @@ class ConfigTranslationBlockListBuilder extends ConfigTranslationEntityListBuild
$theme = $entity->getTheme();
$plugin_definition = $entity->getPlugin()->getPluginDefinition();
$row['label'] = array(
$row['label'] = [
'data' => $entity->label(),
'class' => 'table-filter-text-source',
);
];
$row['theme'] = array(
$row['theme'] = [
'data' => $this->themes[$theme]->info['name'],
'class' => 'table-filter-text-source',
);
];
$row['category'] = array(
$row['category'] = [
'data' => $plugin_definition['category'],
'class' => 'table-filter-text-source',
);
];
$row['operations']['data'] = $this->buildOperations($entity);
@ -93,7 +93,7 @@ class ConfigTranslationBlockListBuilder extends ConfigTranslationEntityListBuild
* {@inheritdoc}
*/
public function sortRows($a, $b) {
return $this->sortRowsMultiple($a, $b, array('theme', 'category', 'label'));
return $this->sortRowsMultiple($a, $b, ['theme', 'category', 'label']);
}
}

View file

@ -134,12 +134,12 @@ class ConfigTranslationController extends ControllerBase {
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRouteMatch($route_match);
$page = array();
$page['#title'] = $this->t('Translations for %label', array('%label' => $mapper->getTitle()));
$page = [];
$page['#title'] = $this->t('Translations for %label', ['%label' => $mapper->getTitle()]);
$languages = $this->languageManager->getLanguages();
if (count($languages) == 1) {
drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', array(':url' => $this->url('entity.configurable_language.collection'))), 'warning');
drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => $this->url('entity.configurable_language.collection')]), 'warning');
}
try {
@ -172,7 +172,7 @@ class ConfigTranslationController extends ControllerBase {
// If the language is not configured on the site, create a dummy language
// object for this listing only to ensure the user gets useful info.
$language_name = $this->languageManager->getLanguageName($original_langcode);
$languages[$original_langcode] = new Language(array('id' => $original_langcode, 'name' => $language_name));
$languages[$original_langcode] = new Language(['id' => $original_langcode, 'name' => $language_name]);
}
// We create a fake request object to pass into
@ -181,10 +181,10 @@ class ConfigTranslationController extends ControllerBase {
// possible nor performant.
$fake_request = $request->duplicate();
$page['languages'] = array(
$page['languages'] = [
'#type' => 'table',
'#header' => array($this->t('Language'), $this->t('Operations')),
);
'#header' => [$this->t('Language'), $this->t('Operations')],
];
foreach ($languages as $language) {
$langcode = $language->getId();
@ -198,57 +198,57 @@ class ConfigTranslationController extends ControllerBase {
// Prepare the language name and the operations depending on whether this
// is the original language or not.
if ($langcode == $original_langcode) {
$language_name = '<strong>' . $this->t('@language (original)', array('@language' => $language->getName())) . '</strong>';
$language_name = '<strong>' . $this->t('@language (original)', ['@language' => $language->getName()]) . '</strong>';
// Check access for the path/route for editing, so we can decide to
// include a link to edit or not.
$edit_access = $this->accessManager->checkNamedRoute($mapper->getBaseRouteName(), $route_match->getRawParameters()->all(), $this->account);
// Build list of operations.
$operations = array();
$operations = [];
if ($edit_access) {
$operations['edit'] = array(
$operations['edit'] = [
'title' => $this->t('Edit'),
'url' => Url::fromRoute($mapper->getBaseRouteName(), $mapper->getBaseRouteParameters(), ['query' => ['destination' => $mapper->getOverviewPath()]]),
);
];
}
}
else {
$language_name = $language->getName();
$operations = array();
$operations = [];
// If no translation exists for this language, link to add one.
if (!$mapper->hasTranslation($language)) {
$operations['add'] = array(
$operations['add'] = [
'title' => $this->t('Add'),
'url' => Url::fromRoute($mapper->getAddRouteName(), $mapper->getAddRouteParameters()),
);
];
}
else {
// Otherwise, link to edit the existing translation.
$operations['edit'] = array(
$operations['edit'] = [
'title' => $this->t('Edit'),
'url' => Url::fromRoute($mapper->getEditRouteName(), $mapper->getEditRouteParameters()),
);
];
$operations['delete'] = array(
$operations['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute($mapper->getDeleteRouteName(), $mapper->getDeleteRouteParameters()),
);
];
}
}
$page['languages'][$langcode]['language'] = array(
$page['languages'][$langcode]['language'] = [
'#markup' => $language_name,
);
];
$page['languages'][$langcode]['operations'] = array(
$page['languages'][$langcode]['operations'] = [
'#type' => 'operations',
'#links' => $operations,
// Even if the mapper contains multiple language codes, the source
// configuration can still be edited.
'#access' => ($langcode == $original_langcode) || $operations_access,
);
];
}
return $page;
}

View file

@ -16,10 +16,10 @@ class ConfigTranslationEntityListBuilder extends ConfigEntityListBuilder impleme
* @return array
*/
protected function getFilterLabels() {
return array(
return [
'placeholder' => $this->t('Enter label'),
'description' => $this->t('Enter a part of the label or description to filter by.'),
);
];
}
/**
@ -29,28 +29,28 @@ class ConfigTranslationEntityListBuilder extends ConfigEntityListBuilder impleme
$build = parent::render();
$filter = $this->getFilterLabels();
usort($build['table']['#rows'], array($this, 'sortRows'));
usort($build['table']['#rows'], [$this, 'sortRows']);
$build['filters'] = array(
$build['filters'] = [
'#type' => 'container',
'#attributes' => array(
'class' => array('table-filter', 'js-show'),
),
'#attributes' => [
'class' => ['table-filter', 'js-show'],
],
'#weight' => -10,
);
];
$build['filters']['text'] = array(
$build['filters']['text'] = [
'#type' => 'search',
'#title' => $this->t('Search'),
'#size' => 30,
'#placeholder' => $filter['placeholder'],
'#attributes' => array(
'class' => array('table-filter-text'),
'#attributes' => [
'class' => ['table-filter-text'],
'data-table' => '.config-translation-entity-list',
'autocomplete' => 'off',
'title' => $filter['description'],
),
);
],
];
$build['table']['#attributes']['class'][] = 'config-translation-entity-list';
$build['table']['#weight'] = 0;
@ -95,7 +95,7 @@ class ConfigTranslationEntityListBuilder extends ConfigEntityListBuilder impleme
* {@inheritdoc}
*/
public function sortRows($a, $b) {
return $this->sortRowsMultiple($a, $b, array('label'));
return $this->sortRowsMultiple($a, $b, ['label']);
}
/**

View file

@ -26,14 +26,14 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
*
* @var array
*/
protected $baseEntityInfo = array();
protected $baseEntityInfo = [];
/**
* The bundle info for the base entity type.
*
* @var array
*/
protected $baseEntityBundles = array();
protected $baseEntityBundles = [];
/**
* The entity manager.
@ -99,8 +99,8 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
$bundle = $this->baseEntityInfo->getBundleLabel() ?: $this->t('Bundle');
$bundle = Unicode::strtolower($bundle);
$info['placeholder'] = $this->t('Enter field or @bundle', array('@bundle' => $bundle));
$info['description'] = $this->t('Enter a part of the field or @bundle to filter by.', array('@bundle' => $bundle));
$info['placeholder'] = $this->t('Enter field or @bundle', ['@bundle' => $bundle]);
$info['description'] = $this->t('Enter a part of the field or @bundle to filter by.', ['@bundle' => $bundle]);
return $info;
}
@ -109,17 +109,17 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = array(
$row['label'] = [
'data' => $entity->label(),
'class' => 'table-filter-text-source',
);
];
if ($this->displayBundle()) {
$bundle = $entity->get('bundle');
$row['bundle'] = array(
$row['bundle'] = [
'data' => $this->baseEntityBundles[$bundle]['label'],
'class' => 'table-filter-text-source',
);
];
}
return $row + parent::buildRow($entity);
@ -165,7 +165,7 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
* {@inheritdoc}
*/
public function sortRows($a, $b) {
return $this->sortRowsMultiple($a, $b, array('bundle', 'label'));
return $this->sortRowsMultiple($a, $b, ['bundle', 'label']);
}
}

View file

@ -46,13 +46,13 @@ class ConfigTranslationMapperList extends ControllerBase {
* Renderable array with config translation mappers.
*/
public function render() {
$build = array(
$build = [
'#type' => 'table',
'#header' => $this->buildHeader(),
'#rows' => array(),
);
'#rows' => [],
];
$mappers = array();
$mappers = [];
foreach ($this->mappers as $mapper) {
if ($row = $this->buildRow($mapper)) {
@ -120,10 +120,10 @@ class ConfigTranslationMapperList extends ControllerBase {
// Retrieve and sort operations.
$operations = $mapper->getOperations();
uasort($operations, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
$build = array(
$build = [
'#type' => 'operations',
'#links' => $operations,
);
];
return $build;
}

View file

@ -22,10 +22,10 @@ class ConfigTranslationAddForm extends ConfigTranslationFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $route_match, $plugin_id, $langcode);
$form['#title'] = $this->t('Add @language translation for %label', array(
$form['#title'] = $this->t('Add @language translation for %label', [
'%label' => $this->mapper->getTitle(),
'@language' => $this->language->getName(),
));
]);
return $form;
}
@ -34,7 +34,7 @@ class ConfigTranslationAddForm extends ConfigTranslationFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->getName())));
drupal_set_message($this->t('Successfully saved @language translation.', ['@language' => $this->language->getName()]));
}
}

View file

@ -84,7 +84,7 @@ class ConfigTranslationDeleteForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the @language translation of %label?', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()));
return $this->t('Are you sure you want to delete the @language translation of %label?', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]);
}
/**
@ -140,7 +140,7 @@ class ConfigTranslationDeleteForm extends ConfirmFormBase {
$cache_backend->deleteAll();
}
drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName())));
drupal_set_message($this->t('@language translation of %label was deleted', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]));
$form_state->setRedirectUrl($this->getCancelUrl());
}

View file

@ -22,10 +22,10 @@ class ConfigTranslationEditForm extends ConfigTranslationFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $route_match, $plugin_id, $langcode);
$form['#title'] = $this->t('Edit @language translation for %label', array(
$form['#title'] = $this->t('Edit @language translation for %label', [
'%label' => $this->mapper->getTitle(),
'@language' => $this->language->getName(),
));
]);
return $form;
}
@ -34,7 +34,7 @@ class ConfigTranslationEditForm extends ConfigTranslationFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
drupal_set_message($this->t('Successfully updated @language translation.', array('@language' => $this->language->getName())));
drupal_set_message($this->t('Successfully updated @language translation.', ['@language' => $this->language->getName()]));
}
}

View file

@ -65,7 +65,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
*
* @var array
*/
protected $baseConfigData = array();
protected $baseConfigData = [];
/**
* Constructs a ConfigTranslationFormBase.
@ -164,26 +164,26 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
// Even though this is a nested form, we do not set #tree to TRUE because
// the form value structure is generated by using #parents for each element.
// @see \Drupal\config_translation\FormElement\FormElementBase::getElements()
$form['config_names'] = array('#type' => 'container');
$form['config_names'] = ['#type' => 'container'];
foreach ($this->mapper->getConfigNames() as $name) {
$form['config_names'][$name] = array('#type' => 'container');
$form['config_names'][$name] = ['#type' => 'container'];
$schema = $this->typedConfigManager->get($name);
$source_config = $this->baseConfigData[$name];
$translation_config = $this->configFactory()->get($name)->get();
if ($form_element = $this->createFormElement($schema)) {
$parents = array('config_names', $name);
$parents = ['config_names', $name];
$form['config_names'][$name] += $form_element->getTranslationBuild($this->sourceLanguage, $this->language, $source_config, $translation_config, $parents);
}
}
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save translation'),
'#button_type' => 'primary',
);
];
// Set the configuration language back.
$this->languageManager->setConfigOverrideLanguage($original_language);
@ -195,7 +195,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_values = $form_state->getValue(array('translation', 'config_names'));
$form_values = $form_state->getValue(['translation', 'config_names']);
foreach ($this->mapper->getConfigNames() as $name) {
$schema = $this->typedConfigManager->get($name);

View file

@ -16,7 +16,7 @@ class DateFormat extends FormElementBase {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$description = $this->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.');
$format = $this->t('Displayed as %date_format', array('%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)));
$format = $this->t('Displayed as %date_format', ['%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)]);
return [
'#type' => 'textfield',

View file

@ -64,8 +64,8 @@ abstract class FormElementBase implements ElementInterface {
$build['source'] = $this->getSourceElement($source_language, $source_config);
$build['translation'] = $this->getTranslationElement($translation_language, $source_config, $translation_config);
$build['source']['#parents'] = array_merge(array('source'), $parents);
$build['translation']['#parents'] = array_merge(array('translation'), $parents);
$build['source']['#parents'] = array_merge(['source'], $parents);
$build['translation']['#parents'] = array_merge(['translation'], $parents);
return $build;
}
@ -93,15 +93,15 @@ abstract class FormElementBase implements ElementInterface {
$value = $this->t('(Empty)');
}
return array(
return [
'#type' => 'item',
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', array(
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', [
// Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition->getLabel()),
'@source_language' => $source_language->getName(),
)),
]),
'#markup' => $value,
);
];
}
/**
@ -157,15 +157,15 @@ abstract class FormElementBase implements ElementInterface {
*/
protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
// Add basic properties that apply to all form elements.
return array(
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', array(
return [
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', [
// Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition->getLabel()),
'@source_language' => $translation_language->getName(),
)),
]),
'#default_value' => $translation_config,
'#attributes' => array('lang' => $translation_language->getId()),
);
'#attributes' => ['lang' => $translation_language->getId()],
];
}
/**

View file

@ -46,14 +46,14 @@ class ListElement implements ElementInterface {
* {@inheritdoc}
*/
public function getTranslationBuild(LanguageInterface $source_language, LanguageInterface $translation_language, $source_config, $translation_config, array $parents, $base_key = NULL) {
$build = array();
$build = [];
foreach ($this->element as $key => $element) {
$sub_build = array();
$sub_build = [];
$element_key = isset($base_key) ? "$base_key.$key" : $key;
$definition = $element->getDataDefinition();
if ($form_element = ConfigTranslationFormBase::createFormElement($element)) {
$element_parents = array_merge($parents, array($key));
$element_parents = array_merge($parents, [$key]);
$sub_build += $form_element->getTranslationBuild($source_language, $translation_language, $source_config[$key], $translation_config[$key], $element_parents, $element_key);
if (empty($sub_build)) {
@ -62,13 +62,13 @@ class ListElement implements ElementInterface {
// Build the sub-structure and include it with a wrapper in the form if
// there are any translatable elements there.
$build[$key] = array();
$build[$key] = [];
if ($element instanceof TraversableTypedDataInterface) {
$build[$key] = array(
$build[$key] = [
'#type' => 'details',
'#title' => $this->getGroupTitle($definition, $sub_build),
'#open' => empty($base_key),
);
];
}
$build[$key] += $sub_build;
}

View file

@ -18,25 +18,25 @@ class PluralVariants extends FormElementBase {
protected function getSourceElement(LanguageInterface $source_language, $source_config) {
$plurals = $this->getNumberOfPlurals($source_language->getId());
$values = explode(LOCALE_PLURAL_DELIMITER, $source_config);
$element = array(
$element = [
'#type' => 'fieldset',
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@source_language)</span>', array(
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@source_language)</span>', [
// Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition->getLabel()),
'@source_language' => $source_language->getName(),
)),
]),
'#tree' => TRUE,
);
];
for ($i = 0; $i < $plurals; $i++) {
$element[$i] = array(
$element[$i] = [
'#type' => 'item',
// @todo Should use better labels https://www.drupal.org/node/2499639
'#title' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'),
'#markup' => SafeMarkup::format('<span lang="@langcode">@value</span>', array(
'#markup' => SafeMarkup::format('<span lang="@langcode">@value</span>', [
'@langcode' => $source_language->getId(),
'@value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'),
)),
);
]),
];
}
return $element;
}
@ -47,23 +47,23 @@ class PluralVariants extends FormElementBase {
protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
$plurals = $this->getNumberOfPlurals($translation_language->getId());
$values = explode(LOCALE_PLURAL_DELIMITER, $translation_config);
$element = array(
$element = [
'#type' => 'fieldset',
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@translation_language)</span>', array(
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@translation_language)</span>', [
// Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition->getLabel()),
'@translation_language' => $translation_language->getName(),
)),
]),
'#tree' => TRUE,
);
];
for ($i = 0; $i < $plurals; $i++) {
$element[$i] = array(
$element[$i] = [
'#type' => 'textfield',
// @todo Should use better labels https://www.drupal.org/node/2499639
'#title' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'),
'#default_value' => isset($values[$i]) ? $values[$i] : '',
'#attributes' => array('lang' => $translation_language->getId()),
);
'#attributes' => ['lang' => $translation_language->getId()],
];
}
return $element;
}

View file

@ -16,25 +16,25 @@ class TextFormat extends FormElementBase {
// Instead of the formatted output show a disabled textarea. This allows for
// easier side-by-side comparison, especially with formats with text
// editors.
return $this->getTranslationElement($source_language, $source_config, $source_config) + array(
return $this->getTranslationElement($source_language, $source_config, $source_config) + [
'#value' => $source_config['value'],
'#disabled' => TRUE,
'#allow_focus' => TRUE,
);
];
}
/**
* {@inheritdoc}
*/
public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
return array(
return [
'#type' => 'text_format',
// Override the #default_value property from the parent class.
'#default_value' => $translation_config['value'],
'#format' => $translation_config['format'],
// @see \Drupal\config_translation\Element\FormElementBase::getTranslationElement()
'#allowed_formats' => array($source_config['format']),
) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
'#allowed_formats' => [$source_config['format']],
] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
}

View file

@ -18,10 +18,10 @@ class Textarea extends FormElementBase {
$rows_newlines = substr_count($translation_config, "\n" ) + 1;
$rows = max($rows_words, $rows_newlines);
return array(
return [
'#type' => 'textarea',
'#rows' => $rows,
) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
}

View file

@ -13,9 +13,9 @@ class Textfield extends FormElementBase {
* {@inheritdoc}
*/
public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
return array(
return [
'#type' => 'textfield',
) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
}

View file

@ -28,7 +28,7 @@ class ConfigTranslationContextualLink extends ContextualLinkDefault {
// storing the title on the plugin definition for the link) because it
// contains translated parts that we need in the runtime language.
$type_name = Unicode::strtolower($this->mapperManager()->createInstance($this->pluginDefinition['config_translation_plugin_id'])->getTypeLabel());
return $this->t('Translate @type_name', array('@type_name' => $type_name));
return $this->t('Translate @type_name', ['@type_name' => $type_name]);
}
/**

View file

@ -28,7 +28,7 @@ class ConfigTranslationLocalTask extends LocalTaskDefault {
// storing the title on the plugin definition for the link) because
// it contains translated parts that we need in the runtime language.
$type_name = Unicode::strtolower($this->mapperManager()->createInstance($this->pluginDefinition['config_translation_plugin_id'])->getTypeLabel());
return $this->t('Translate @type_name', array('@type_name' => $type_name));
return $this->t('Translate @type_name', ['@type_name' => $type_name]);
}
/**

View file

@ -0,0 +1,53 @@
<?php
namespace Drupal\config_translation\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* i18n strings profile field source from database.
*
* @MigrateSource(
* id = "d6_i18n_profile_field",
* source_provider = "i18n"
* )
*/
class I18nProfileField extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('profile_fields', 'pf')
->fields('pf', ['fid', 'name'])
->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language']);
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'fid' => $this->t('Profile field ID.'),
'lid' => $this->t('Locales target language ID.'),
'language' => $this->t('Language for this field.'),
'translation' => $this->t('Translation of either the title or explanation.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}

View file

@ -48,7 +48,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*/
public static function getSubscribedEvents() {
// Come after field_ui.
$events[RoutingEvents::ALTER] = array('onAlterRoutes', -110);
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -110];
return $events;
}

View file

@ -17,7 +17,7 @@ class ConfigTranslationFormTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('config_translation', 'config_translation_test', 'editor');
public static $modules = ['config_translation', 'config_translation_test', 'editor'];
/**
* The plugin ID of the mapper to test.
@ -40,7 +40,7 @@ class ConfigTranslationFormTest extends WebTestBase {
$this->pluginId = key($definitions);
$this->langcode = 'xx';
ConfigurableLanguage::create(array('id' => $this->langcode, 'label' => 'XX'))->save();
ConfigurableLanguage::create(['id' => $this->langcode, 'label' => 'XX'])->save();
\Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
}

View file

@ -63,7 +63,7 @@ ENDPO;
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'fr'], t('Add custom language'));
$edit = [
'modules[Multilingual][config_translation][enable]' => TRUE,
'modules[config_translation][enable]' => TRUE,
];
$this->drupalPostForm('admin/modules', $edit, t('Install'));

View file

@ -35,7 +35,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
*
* @var array
*/
protected $langcodes = array('fr', 'ta');
protected $langcodes = ['fr', 'ta'];
/**
* String translation storage object.
@ -46,7 +46,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$permissions = array(
$permissions = [
'translate configuration',
'administer languages',
'administer site configuration',
@ -54,7 +54,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
'access site-wide contact form',
'access contextual links',
'administer views',
);
];
// Create and log in user.
$this->drupalLogin($this->drupalCreateUser($permissions));
@ -83,17 +83,17 @@ class ConfigTranslationOverviewTest extends WebTestBase {
}
}
$labels = array(
$labels = [
'&$nxd~i0',
'some "label" with quotes',
$this->randomString(),
);
];
foreach ($labels as $label) {
$test_entity = entity_create('config_test', array(
$test_entity = entity_create('config_test', [
'id' => $this->randomMachineName(),
'label' => $label,
));
]);
$test_entity->save();
$base_url = 'admin/structure/config_test/manage/' . $test_entity->id();
@ -119,7 +119,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
$this->assertRaw('<th>' . t('Language') . '</th>');
$this->drupalGet($base_url);
$this->assertLink(t('Translate @title', array('@title' => $entity_type->getLowercaseLabel())));
$this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
}
}
@ -154,10 +154,10 @@ class ConfigTranslationOverviewTest extends WebTestBase {
$config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
// Set up an override.
$settings['config']['config_test.dynamic.dotted.default']['label'] = (object) array(
$settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
'value' => $overridden_label,
'required' => TRUE,
);
];
$this->writeSettings($settings);
// Test that the overridden label is loaded with the entity.

View file

@ -48,7 +48,7 @@ class ConfigTranslationUiTest extends WebTestBase {
*
* @var array
*/
protected $langcodes = array('fr', 'ta');
protected $langcodes = ['fr', 'ta'];
/**
* Administrator user for tests.
@ -157,13 +157,13 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertRaw($site_slogan);
// Update site name and slogan for French.
$edit = array(
$edit = [
'translation[config_names][system.site][name]' => $fr_site_name,
'translation[config_names][system.site][slogan]' => $fr_site_slogan,
);
];
$this->drupalPostForm("$translation_base_url/fr/add", $edit, t('Save translation'));
$this->assertRaw(t('Successfully saved @language translation.', array('@language' => 'French')));
$this->assertRaw(t('Successfully saved @language translation.', ['@language' => 'French']));
// Check for edit, delete links (and no 'add' link) for French language.
$this->assertNoLinkByHref("$translation_base_url/fr/add");
@ -189,18 +189,18 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertText($site_slogan);
// Translate 'Site name' label in French.
$search = array(
$search = [
'string' => $site_name_label,
'langcode' => 'fr',
'translation' => 'untranslated',
);
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$textarea = current($this->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$edit = [
$lid => $fr_site_name_label,
);
];
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
// Ensure that the label is in French (and not in English).
@ -234,10 +234,10 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalGet($translation_base_url);
// Case 1: Update new value for site slogan and site name.
$edit = array(
$edit = [
'translation[config_names][system.site][name]' => 'FR ' . $site_name,
'translation[config_names][system.site][slogan]' => 'FR ' . $site_slogan,
);
];
// First time, no overrides, so just Add link.
$this->drupalPostForm("$translation_base_url/fr/add", $edit, t('Save translation'));
@ -245,10 +245,10 @@ class ConfigTranslationUiTest extends WebTestBase {
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
// Expect both name and slogan in language specific file.
$expected = array(
$expected = [
'name' => 'FR ' . $site_name,
'slogan' => 'FR ' . $site_slogan,
);
];
$this->assertEqual($expected, $override->get());
// Case 2: Update new value for site slogan and default value for site name.
@ -257,12 +257,12 @@ class ConfigTranslationUiTest extends WebTestBase {
// translation form into the actual site name and slogan.
$this->assertNoText('FR ' . $site_name);
$this->assertNoText('FR ' . $site_slogan);
$edit = array(
$edit = [
'translation[config_names][system.site][name]' => $site_name,
'translation[config_names][system.site][slogan]' => 'FR ' . $site_slogan,
);
];
$this->drupalPostForm(NULL, $edit, t('Save translation'));
$this->assertRaw(t('Successfully updated @language translation.', array('@language' => 'French')));
$this->assertRaw(t('Successfully updated @language translation.', ['@language' => 'French']));
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
// Expect only slogan in language specific file.
@ -272,10 +272,10 @@ class ConfigTranslationUiTest extends WebTestBase {
// Case 3: Keep default value for site name and slogan.
$this->drupalGet("$translation_base_url/fr/edit");
$this->assertNoText('FR ' . $site_slogan);
$edit = array(
$edit = [
'translation[config_names][system.site][name]' => $site_name,
'translation[config_names][system.site][slogan]' => $site_slogan,
);
];
$this->drupalPostForm(NULL, $edit, t('Save translation'));
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
@ -310,11 +310,11 @@ class ConfigTranslationUiTest extends WebTestBase {
// Save default language configuration.
$label = 'Send your feedback';
$edit = array(
$edit = [
'label' => $label,
'recipients' => 'sales@example.com,support@example.com',
'reply' => 'Thank you for your mail',
);
];
$this->drupalPostForm('admin/structure/contact/manage/feedback', $edit, t('Save'));
// Ensure translation link is present.
@ -323,7 +323,7 @@ class ConfigTranslationUiTest extends WebTestBase {
// Make sure translate tab is present.
$this->drupalGet('admin/structure/contact/manage/feedback');
$this->assertLink(t('Translate @type', array('@type' => 'contact form')));
$this->assertLink(t('Translate @type', ['@type' => 'contact form']));
// Visit the form to confirm the changes.
$this->drupalGet('contact/feedback');
@ -331,7 +331,7 @@ class ConfigTranslationUiTest extends WebTestBase {
foreach ($this->langcodes as $langcode) {
$this->drupalGet($translation_base_url);
$this->assertLink(t('Translate @type', array('@type' => 'contact form')));
$this->assertLink(t('Translate @type', ['@type' => 'contact form']));
// 'Add' link should be present for $langcode translation.
$translation_page_url = "$translation_base_url/$langcode/add";
@ -342,20 +342,20 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertText($label);
// Update translatable fields.
$edit = array(
$edit = [
'translation[config_names][contact.form.feedback][label]' => 'Website feedback - ' . $langcode,
'translation[config_names][contact.form.feedback][reply]' => 'Thank you for your mail - ' . $langcode,
);
];
// Save language specific version of form.
$this->drupalPostForm($translation_page_url, $edit, t('Save translation'));
// Expect translated values in language specific file.
$override = \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'contact.form.feedback');
$expected = array(
$expected = [
'label' => 'Website feedback - ' . $langcode,
'reply' => 'Thank you for your mail - ' . $langcode,
);
];
$this->assertEqual($expected, $override->get());
// Check for edit, delete links (and no 'add' link) for $langcode.
@ -368,10 +368,10 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertText('Website feedback - ' . $langcode);
// Submit feedback.
$edit = array(
$edit = [
'subject[0][value]' => 'Test subject',
'message[0][value]' => 'Test message',
);
];
$this->drupalPostForm(NULL, $edit, t('Send message'));
}
@ -379,7 +379,7 @@ class ConfigTranslationUiTest extends WebTestBase {
// original text all appear in any translated page on the translation
// forms.
foreach ($this->langcodes as $langcode) {
$langcode_prefixes = array_merge(array(''), $this->langcodes);
$langcode_prefixes = array_merge([''], $this->langcodes);
foreach ($langcode_prefixes as $langcode_prefix) {
$this->drupalGet(ltrim("$langcode_prefix/$translation_base_url/$langcode/edit", '/'));
$this->assertFieldByName('translation[config_names][contact.form.feedback][label]', 'Website feedback - ' . $langcode);
@ -400,14 +400,14 @@ class ConfigTranslationUiTest extends WebTestBase {
// Test that delete links work and operations perform properly.
foreach ($this->langcodes as $langcode) {
$replacements = array('%label' => t('@label @entity_type', array('@label' => $label, '@entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => \Drupal::languageManager()->getLanguage($langcode)->getName());
$replacements = ['%label' => t('@label @entity_type', ['@label' => $label, '@entity_type' => Unicode::strtolower(t('Contact form'))]), '@language' => \Drupal::languageManager()->getLanguage($langcode)->getName()];
$this->drupalGet("$translation_base_url/$langcode/delete");
$this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements));
// Assert link back to list page to cancel delete is present.
$this->assertLinkByHref($translation_base_url);
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->drupalPostForm(NULL, [], t('Delete'));
$this->assertRaw(t('@language translation of %label was deleted', $replacements));
$this->assertLinkByHref("$translation_base_url/$langcode/add");
$this->assertNoLinkByHref("translation_base_url/$langcode/edit");
@ -445,18 +445,18 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertLinkByHref('admin/config/regional/date-time/formats/manage/medium');
// Save default language configuration for a new format.
$edit = array(
$edit = [
'label' => 'Custom medium date',
'id' => 'custom_medium',
'date_format_pattern' => 'Y. m. d. H:i',
);
];
$this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
// Test translating a default shipped format and our custom format.
$formats = array(
$formats = [
'medium' => 'Default medium date',
'custom_medium' => 'Custom medium date',
);
];
foreach ($formats as $id => $label) {
$translation_base_url = 'admin/config/regional/date-time/formats/manage/' . $id . '/translate';
@ -474,20 +474,20 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertRaw('core/modules/system/js/system.date.js');
// Update translatable fields.
$edit = array(
$edit = [
'translation[config_names][core.date_format.' . $id . '][label]' => $id . ' - FR',
'translation[config_names][core.date_format.' . $id . '][pattern]' => 'D',
);
];
// Save language specific version of form.
$this->drupalPostForm($translation_page_url, $edit, t('Save translation'));
// Get translation and check we've got the right value.
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'core.date_format.' . $id);
$expected = array(
$expected = [
'label' => $id . ' - FR',
'pattern' => 'D',
);
];
$this->assertEqual($expected, $override->get());
// Formatting the date 8 / 27 / 1985 @ 13:37 EST with pattern D should
@ -508,18 +508,18 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/people/accounts');
$this->assertLink(t('Translate @type', array('@type' => 'account settings')));
$this->assertLink(t('Translate @type', ['@type' => 'account settings']));
$this->drupalGet('admin/config/people/accounts/translate');
$this->assertLink(t('Translate @type', array('@type' => 'account settings')));
$this->assertLink(t('Translate @type', ['@type' => 'account settings']));
$this->assertLinkByHref('admin/config/people/accounts/translate/fr/add');
// Update account settings fields for French.
$edit = array(
$edit = [
'translation[config_names][user.settings][anonymous]' => 'Anonyme',
'translation[config_names][user.mail][status_blocked][subject]' => 'Testing, your account is blocked.',
'translation[config_names][user.mail][status_blocked][body]' => 'Testing account blocked body.',
);
];
$this->drupalPostForm('admin/config/people/accounts/translate/fr/add', $edit, t('Save translation'));
@ -588,7 +588,7 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
// Assert contextual link related to views.
$ids = array('entity.view.edit_form:view=frontpage:location=page&name=frontpage&display_id=page_1');
$ids = ['entity.view.edit_form:view=frontpage:location=page&name=frontpage&display_id=page_1'];
$response = $this->renderContextualLinks($ids, 'node');
$this->assertResponse(200);
$json = Json::decode($response);
@ -611,14 +611,14 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertRaw($human_readable_name);
// Update Views Fields for French.
$edit = array(
$edit = [
'translation[config_names][views.view.frontpage][description]' => $description . " FR",
'translation[config_names][views.view.frontpage][label]' => $human_readable_name . " FR",
'translation[config_names][views.view.frontpage][display][default][display_title]' => $display_settings_master . " FR",
'translation[config_names][views.view.frontpage][display][default][display_options][title]' => $display_options_master . " FR",
);
];
$this->drupalPostForm("$translation_base_url/fr/add", $edit, t('Save translation'));
$this->assertRaw(t('Successfully saved @language translation.', array('@language' => 'French')));
$this->assertRaw(t('Successfully saved @language translation.', ['@language' => 'French']));
// Check for edit, delete links (and no 'add' link) for French language.
$this->assertNoLinkByHref("$translation_base_url/fr/add");
@ -640,20 +640,20 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
// Languages to test, with various number of plural forms.
$languages = array(
'vi' => array('plurals' => 1, 'expected' => array(TRUE, FALSE, FALSE, FALSE)),
'fr' => array('plurals' => 2, 'expected' => array(TRUE, TRUE, FALSE, FALSE)),
'sl' => array('plurals' => 4, 'expected' => array(TRUE, TRUE, TRUE, TRUE)),
);
$languages = [
'vi' => ['plurals' => 1, 'expected' => [TRUE, FALSE, FALSE, FALSE]],
'fr' => ['plurals' => 2, 'expected' => [TRUE, TRUE, FALSE, FALSE]],
'sl' => ['plurals' => 4, 'expected' => [TRUE, TRUE, TRUE, TRUE]],
];
foreach ($languages as $langcode => $data) {
// Import a .po file to add a new language with a given number of plural forms
$name = \Drupal::service('file_system')->tempnam('temporary://', $langcode . '_') . '.po';
file_put_contents($name, $this->getPoFile($data['plurals']));
$this->drupalPostForm('admin/config/regional/translate/import', array(
$this->drupalPostForm('admin/config/regional/translate/import', [
'langcode' => $langcode,
'files[file]' => $name,
), t('Import'));
], t('Import'));
// Change the config langcode of the 'files' view.
$config = \Drupal::service('config.factory')->getEditable('views.view.files');
@ -686,10 +686,10 @@ class ConfigTranslationUiTest extends WebTestBase {
// This will also automatically add the 'sl' language.
$name = \Drupal::service('file_system')->tempnam('temporary://', "sl_") . '.po';
file_put_contents($name, $this->getPoFile(4));
$this->drupalPostForm('admin/config/regional/translate/import', array(
$this->drupalPostForm('admin/config/regional/translate/import', [
'langcode' => 'sl',
'files[file]' => $name,
), t('Import'));
], t('Import'));
// Translate the files view, as this one uses numeric formatters.
$description = 'Singular form';
@ -817,12 +817,12 @@ class ConfigTranslationUiTest extends WebTestBase {
$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'));
// Make sure there is no translation stored in locale storage before edit.
@ -830,9 +830,9 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertTrue(empty($translation));
// Add custom translation.
$edit = array(
$edit = [
'translation[config_names][user.settings][anonymous]' => 'Anonyme',
);
];
$this->drupalPostForm('admin/config/people/accounts/translate/fr/add', $edit, t('Save translation'));
// Make sure translation stored in locale storage after saved language
@ -841,9 +841,9 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertEqual('Anonyme', $translation->getString());
// revert custom translations to base translation.
$edit = array(
$edit = [
'translation[config_names][user.settings][anonymous]' => 'Anonymous',
);
];
$this->drupalPostForm('admin/config/people/accounts/translate/fr/edit', $edit, t('Save translation'));
// Make sure there is no translation stored in locale storage after revert.
@ -858,19 +858,19 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
// Delete French language
$this->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('Delete'));
$this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'French', '%langcode' => 'fr')));
$this->drupalPostForm('admin/config/regional/language/delete/fr', [], t('Delete'));
$this->assertRaw(t('The %language (%langcode) language has been removed.', ['%language' => 'French', '%langcode' => 'fr']));
// Change default language to Tamil.
$edit = array(
$edit = [
'site_default_language' => 'ta',
);
];
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
$this->assertRaw(t('Configuration saved.'));
// Delete English language
$this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
$this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'English', '%langcode' => 'en')));
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
$this->assertRaw(t('The %language (%langcode) language has been removed.', ['%language' => 'English', '%langcode' => 'en']));
// Visit account setting translation page, this should not
// throw any notices.
@ -907,32 +907,32 @@ class ConfigTranslationUiTest extends WebTestBase {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $this->container->get('config.factory');
$expected = array(
$expected = [
'kitten',
'llama',
'elephant'
);
];
$actual = $config_factory
->getEditable('config_translation_test.content')
->get('animals');
$this->assertEqual($expected, $actual);
$edit = array(
$edit = [
'translation[config_names][config_translation_test.content][content][value]' => '<p><strong>Hello World</strong> - FR</p>',
'translation[config_names][config_translation_test.content][animals][0]' => 'kitten - FR',
'translation[config_names][config_translation_test.content][animals][1]' => 'llama - FR',
'translation[config_names][config_translation_test.content][animals][2]' => 'elephant - FR',
);
];
$this->drupalPostForm('admin/config/media/file-system/translate/fr/add', $edit, t('Save translation'));
$this->container->get('language.config_factory_override')
->setLanguage(new Language(array('id' => 'fr')));
->setLanguage(new Language(['id' => 'fr']));
$expected = array(
$expected = [
'kitten - FR',
'llama - FR',
'elephant - FR',
);
];
$actual = $config_factory
->get('config_translation_test.content')
->get('animals');
@ -947,10 +947,10 @@ class ConfigTranslationUiTest extends WebTestBase {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $this->container->get('config.factory');
$expected = array(
$expected = [
'value' => '<p><strong>Hello World</strong></p>',
'format' => 'plain_text',
);
];
$actual = $config_factory
->get('config_translation_test.content')
->getOriginal('content', FALSE);
@ -970,20 +970,20 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertNoFieldByName('translation[config_names][config_translation_test.content][content][format]');
// Update translatable fields.
$edit = array(
$edit = [
'translation[config_names][config_translation_test.content][content][value]' => '<p><strong>Hello World</strong> - FR</p>',
);
];
// Save language specific version of form.
$this->drupalPostForm($translation_page_url, $edit, t('Save translation'));
// Get translation and check we've got the right value.
$expected = array(
$expected = [
'value' => '<p><strong>Hello World</strong> - FR</p>',
'format' => 'plain_text',
);
];
$this->container->get('language.config_factory_override')
->setLanguage(new Language(array('id' => 'fr')));
->setLanguage(new Language(['id' => 'fr']));
$actual = $config_factory
->get('config_translation_test.content')
->get('content');
@ -1009,7 +1009,7 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->drupalLogin($this->translatorUser);
$this->drupalGet($translation_page_url);
$this->assertDisabledTextarea('edit-translation-config-names-config-translation-testcontent-content-value');
$this->drupalPostForm(NULL, array(), t('Save translation'));
$this->drupalPostForm(NULL, [], t('Save translation'));
// Check that submitting the form did not update the text format of the
// translation.
$actual = $config_factory
@ -1019,14 +1019,14 @@ class ConfigTranslationUiTest extends WebTestBase {
// The administrator must explicitly change the text format.
$this->drupalLogin($this->adminUser);
$edit = array(
$edit = [
'translation[config_names][config_translation_test.content][content][format]' => 'full_html',
);
];
$this->drupalPostForm($translation_page_url, $edit, t('Save translation'));
$expected = array(
$expected = [
'value' => '<p><strong>Hello World</strong> - FR</p>',
'format' => 'full_html',
);
];
$actual = $config_factory
->get('config_translation_test.content')
->get('content');
@ -1047,20 +1047,20 @@ class ConfigTranslationUiTest extends WebTestBase {
* Returns translation if exists, FALSE otherwise.
*/
protected function getTranslation($config_name, $key, $langcode) {
$settings_locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $config_name));
$this->assertTrue(!empty($settings_locations), format_string('Configuration locations found for %config_name.', array('%config_name' => $config_name)));
$settings_locations = $this->localeStorage->getLocations(['type' => 'configuration', 'name' => $config_name]);
$this->assertTrue(!empty($settings_locations), format_string('Configuration locations found for %config_name.', ['%config_name' => $config_name]));
if (!empty($settings_locations)) {
$source = $this->container->get('config.factory')->get($config_name)->get($key);
$source_string = $this->localeStorage->findString(array('source' => $source, 'type' => 'configuration'));
$this->assertTrue(!empty($source_string), format_string('Found string for %config_name.%key.', array('%config_name' => $config_name, '%key' => $key)));
$source_string = $this->localeStorage->findString(['source' => $source, 'type' => 'configuration']);
$this->assertTrue(!empty($source_string), format_string('Found string for %config_name.%key.', ['%config_name' => $config_name, '%key' => $key]));
if (!empty($source_string)) {
$conditions = array(
$conditions = [
'lid' => $source_string->lid,
'language' => $langcode,
);
$translations = $this->localeStorage->getTranslations($conditions + array('translated' => TRUE));
];
$translations = $this->localeStorage->getTranslations($conditions + ['translated' => TRUE]);
return reset($translations);
}
}
@ -1074,10 +1074,10 @@ class ConfigTranslationUiTest extends WebTestBase {
* @param string $site_slogan
*/
protected function setSiteInformation($site_name, $site_slogan) {
$edit = array(
$edit = [
'site_name' => $site_name,
'site_slogan' => $site_slogan,
);
];
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this->assertRaw(t('The configuration options have been saved.'));
}
@ -1094,11 +1094,11 @@ class ConfigTranslationUiTest extends WebTestBase {
* The response body.
*/
protected function renderContextualLinks($ids, $current_path) {
$post = array();
$post = [];
for ($i = 0; $i < count($ids); $i++) {
$post['ids[' . $i . ']'] = $ids[$i];
}
return $this->drupalPostWithFormat('contextual/render', 'json', $post, array('query' => array('destination' => $current_path)));
return $this->drupalPostWithFormat('contextual/render', 'json', $post, ['query' => ['destination' => $current_path]]);
}
/**
@ -1111,30 +1111,30 @@ class ConfigTranslationUiTest extends WebTestBase {
* TRUE if the assertion passed; FALSE otherwise.
*/
protected function assertDisabledTextarea($id) {
$textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', array(
$textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [
':id' => $id,
));
]);
$textarea = reset($textarea);
$passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', array(
$passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', [
'@id' => $id,
)));
]));
$expected = 'This field has been disabled because you do not have sufficient permissions to edit it.';
$passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', array(
$passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
'@id' => $id,
)));
]));
// Make sure the text format select is not shown.
$select_id = str_replace('value', 'format--2', $id);
$select = $this->xpath('//select[@id=:id]', array(':id' => $select_id));
return $passed && $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', array(
$select = $this->xpath('//select[@id=:id]', [':id' => $select_id]);
return $passed && $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', [
'@id' => $id,
)));
]));
}
/**
* Helper function that returns a .po file with a given number of plural forms.
*/
public function getPoFile($plurals) {
$po_file = array();
$po_file = [];
$po_file[1] = <<< EOF
msgid ""

View file

@ -24,7 +24,7 @@ class ConfigTranslationUiThemeTest extends WebTestBase {
*
* @var array
*/
protected $langcodes = array('fr', 'ta');
protected $langcodes = ['fr', 'ta'];
/**
* Administrator user for tests.

View file

@ -33,7 +33,7 @@ function config_translation_test_entity_type_alter(array &$entity_types) {
function config_translation_test_config_translation_info_alter(&$info) {
if (\Drupal::state()->get('config_translation_test_config_translation_info_alter')) {
// Limit account settings config files to only one of them.
$info['entity.user.admin_form']['names'] = array('user.settings');
$info['entity.user.admin_form']['names'] = ['user.settings'];
// Add one more config file to the site information page.
$info['system.site_information_settings']['names'][] = 'system.rss';

View file

@ -1,22 +1,22 @@
<?php
namespace Drupal\config_translation\Tests;
namespace Drupal\Tests\config_translation\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the content translation behaviours on date formats.
*
* @group config_translation
*/
class ConfigTranslationDateFormatUiTest extends WebTestBase {
class ConfigTranslationDateFormatUiTest extends BrowserTestBase {
public static $modules = array(
public static $modules = [
'language',
'config_translation',
'system'
);
];
protected function setUp() {
parent::setUp();
@ -27,10 +27,10 @@ class ConfigTranslationDateFormatUiTest extends WebTestBase {
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
$user = $this->drupalCreateUser(array(
$user = $this->drupalCreateUser([
'administer site configuration',
'translate configuration',
));
]);
$this->drupalLogin($user);
}

View file

@ -1,13 +1,13 @@
<?php
namespace Drupal\config_translation\Tests;
namespace Drupal\Tests\config_translation\Functional;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\contact\Entity\ContactForm;
use Drupal\filter\Entity\FilterFormat;
@ -19,14 +19,14 @@ use Drupal\taxonomy\Entity\Vocabulary;
* @group config_translation
* @see \Drupal\config_translation\Tests\ConfigTranslationViewListUiTest
*/
class ConfigTranslationListUiTest extends WebTestBase {
class ConfigTranslationListUiTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
public static $modules = [
'block',
'config_translation',
'contact',
@ -40,7 +40,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'image',
'responsive_image',
'toolbar',
);
];
/**
* Admin user with all needed permissions.
@ -52,7 +52,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$permissions = array(
$permissions = [
'access site-wide contact form',
'administer blocks',
'administer contact forms',
@ -70,7 +70,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'administer image styles',
'administer responsive images',
'translate configuration',
);
];
// Create and log in user.
$this->adminUser = $this->drupalCreateUser($permissions);
@ -94,7 +94,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
// Add a test block, any block will do.
// Set the machine name so the translate link can be built later.
$id = Unicode::strtolower($this->randomMachineName(16));
$this->drupalPlaceBlock('system_powered_by_block', array('id' => $id));
$this->drupalPlaceBlock('system_powered_by_block', ['id' => $id]);
// Get the Block listing.
$this->drupalGet('admin/structure/block');
@ -118,11 +118,11 @@ class ConfigTranslationListUiTest extends WebTestBase {
// Lowercase the machine name.
$menu_name = Unicode::strtolower($this->randomMachineName(16));
$label = $this->randomMachineName(16);
$edit = array(
$edit = [
'id' => $menu_name,
'description' => '',
'label' => $label,
);
];
// Create the menu by posting the form.
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
@ -135,9 +135,9 @@ class ConfigTranslationListUiTest extends WebTestBase {
// Check if the Link is not added if you are missing 'translate
// configuration' permission.
$permissions = array(
$permissions = [
'administer menu',
);
];
$this->drupalLogin($this->drupalCreateUser($permissions));
// Get the Menu listing.
@ -186,11 +186,11 @@ class ConfigTranslationListUiTest extends WebTestBase {
public function doCustomContentTypeListTest() {
// Create a test custom block type to decouple looking for translate
// operations link so this does not test more than necessary.
$block_content_type = BlockContentType::create(array(
$block_content_type = BlockContentType::create([
'id' => Unicode::strtolower($this->randomMachineName(16)),
'label' => $this->randomMachineName(),
'revision' => FALSE
));
]);
$block_content_type->save();
// Get the custom block type listing.
@ -235,10 +235,10 @@ class ConfigTranslationListUiTest extends WebTestBase {
public function doContentTypeListTest() {
// Create a test content type to decouple looking for translate operations
// link so this does not test more than necessary.
$content_type = $this->drupalCreateContentType(array(
$content_type = $this->drupalCreateContentType([
'type' => Unicode::strtolower($this->randomMachineName(16)),
'name' => $this->randomMachineName(),
));
]);
// Get the content type listing.
$this->drupalGet('admin/structure/types');
@ -258,10 +258,10 @@ class ConfigTranslationListUiTest extends WebTestBase {
public function doFormatsListTest() {
// Create a test format to decouple looking for translate operations
// link so this does not test more than necessary.
$filter_format = FilterFormat::create(array(
$filter_format = FilterFormat::create([
'format' => Unicode::strtolower($this->randomMachineName(16)),
'name' => $this->randomMachineName(),
));
]);
$filter_format->save();
// Get the format listing.
@ -282,10 +282,10 @@ class ConfigTranslationListUiTest extends WebTestBase {
public function doShortcutListTest() {
// Create a test shortcut to decouple looking for translate operations
// link so this does not test more than necessary.
$shortcut = ShortcutSet::create(array(
$shortcut = ShortcutSet::create([
'id' => Unicode::strtolower($this->randomMachineName(16)),
'label' => $this->randomString(),
));
]);
$shortcut->save();
// Get the shortcut listing.
@ -307,7 +307,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
// Create a test role to decouple looking for translate operations
// link so this does not test more than necessary.
$role_id = Unicode::strtolower($this->randomMachineName(16));
$this->drupalCreateRole(array(), $role_id);
$this->drupalCreateRole([], $role_id);
// Get the role listing.
$this->drupalGet('admin/people/roles');
@ -361,13 +361,13 @@ class ConfigTranslationListUiTest extends WebTestBase {
* Tests the responsive image mapping listing for the translate operation.
*/
public function doResponsiveImageListTest() {
$edit = array();
$edit = [];
$edit['label'] = $this->randomMachineName();
$edit['id'] = strtolower($edit['label']);
$edit['fallback_image_style'] = 'thumbnail';
$this->drupalPostForm('admin/config/media/responsive-image-style/add', $edit, t('Save'));
$this->assertRaw(t('Responsive image style %label saved.', array('%label' => $edit['label'])));
$this->assertRaw(t('Responsive image style %label saved.', ['%label' => $edit['label']]));
// Get the responsive image style listing.
$this->drupalGet('admin/config/media/responsive-image-style');
@ -386,17 +386,17 @@ class ConfigTranslationListUiTest extends WebTestBase {
*/
public function doFieldListTest() {
// Create a base content type.
$content_type = $this->drupalCreateContentType(array(
$content_type = $this->drupalCreateContentType([
'type' => Unicode::strtolower($this->randomMachineName(16)),
'name' => $this->randomMachineName(),
));
]);
// Create a block content type.
$block_content_type = BlockContentType::create(array(
$block_content_type = BlockContentType::create([
'id' => 'basic',
'label' => 'Basic',
'revision' => FALSE
));
]);
$block_content_type->save();
$field = FieldConfig::create([
// The field storage is guaranteed to exist because it is supplied by the
@ -404,21 +404,21 @@ class ConfigTranslationListUiTest extends WebTestBase {
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
'bundle' => $block_content_type->id(),
'label' => 'Body',
'settings' => array('display_summary' => FALSE),
'settings' => ['display_summary' => FALSE],
]);
$field->save();
// Look at a few fields on a few entity types.
$pages = array(
array(
$pages = [
[
'list' => 'admin/structure/types/manage/' . $content_type->id() . '/fields',
'field' => 'node.' . $content_type->id() . '.body',
),
array(
],
[
'list' => 'admin/structure/block/block-content/manage/basic/fields',
'field' => 'block_content.basic.body',
),
);
],
];
foreach ($pages as $values) {
// Get fields listing.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\config_translation\Tests;
namespace Drupal\Tests\config_translation\Functional;
use Drupal\views_ui\Tests\UITestBase;
@ -16,22 +16,22 @@ class ConfigTranslationViewListUiTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('node', 'test_view');
public static $testViews = ['node', 'test_view'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_translation', 'views_ui');
public static $modules = ['config_translation', 'views_ui'];
protected function setUp() {
parent::setUp();
$permissions = array(
$permissions = [
'administer views',
'translate configuration',
);
];
// Create and log in user.
$this->drupalLogin($this->drupalCreateUser($permissions));

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\config_translation\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**

View file

@ -0,0 +1,64 @@
<?php
namespace Drupal\Tests\config_translation\Kernel\Migrate\d6;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests the user profile field instance migration.
*
* @group migrate_drupal_6
*/
class MigrateI18nUserProfileFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['config_translation', 'locale', 'language', 'field'];
/**
* Tests migration of translated user profile fields.
*/
public function testUserProfileFields() {
$this->executeMigrations([
'user_profile_field',
'user_profile_field_instance',
'd6_i18n_user_profile_field_instance',
]);
$language_manager = $this->container->get('language_manager');
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_love_migrations');
$this->assertSame("J'aime les migrations", $config_translation->get('label'));
$this->assertSame("Si vous cochez cette case, vous aimez les migrations.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_color');
$this->assertSame('fr - Favorite color', $config_translation->get('label'));
$this->assertSame('Inscrivez votre couleur préférée', $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_biography');
$this->assertSame('fr - Biography', $config_translation->get('label'));
$this->assertSame('fr - Tell people a little bit about yourself', $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sell_address');
$this->assertSame('fr - Sell your email address?', $config_translation->get('label'));
$this->assertSame("fr - If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sold_to');
$this->assertSame('fr - Sales Category', $config_translation->get('label'));
$this->assertSame("fr - Select the sales categories to which this user's address was sold.", $config_translation->get('description'));
$this->assertSame('fr - Pill spammers Fitness spammers Back\slash Forward/slash Dot.in.the.middle', $config_translation->get('options'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_bands');
$this->assertSame('Mes groupes préférés', $config_translation->get('label'));
$this->assertSame("fr - Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_birthdate');
$this->assertSame('fr - Birthdate', $config_translation->get('label'));
$this->assertSame('fr - Enter your birth date and we\'ll send you a coupon.', $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_blog');
$this->assertSame('fr - Blog', $config_translation->get('label'));
$this->assertSame('fr - Paste the full URL, including http://, of your personal blog.', $config_translation->get('description'));
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace Drupal\Tests\config_translation\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the i18nProfileField source plugin.
*
* @covers \Drupal\config_translation\Plugin\migrate\source\d6\I18nProfileField
* @group migrate_drupal
*/
class I18nProfileFieldTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['config_translation', 'migrate_drupal', 'user'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = [];
$test[0]['source_data'] = [
'profile_fields' => [
[
'fid' => 42,
'title' => 'I love migrations',
'name' => 'profile_love_migrations',
],
],
'i18n_strings' => [
[
'lid' => 10,
'objectid' => 'profile_love_migrations',
'type' => 'field',
'property' => 'title',
],
[
'lid' => 11,
'objectid' => 'profile_love_migrations',
'type' => 'field',
'property' => 'explanation'
]
],
'locales_target' => [
[
'lid' => 10,
'translation' => "J'aime les migrations.",
'language' => 'fr',
],
[
'lid' => 11,
'translation' => 'Si vous cochez cette case, vous aimez les migrations.',
'language' => 'fr',
],
],
];
$test[0]['expected_results'] = [
[
'property' => 'title',
'translation' => "J'aime les migrations.",
'language' => 'fr',
'fid' => '42',
'name' => 'profile_love_migrations',
],
[
'property' => 'explanation',
'translation' => 'Si vous cochez cette case, vous aimez les migrations.',
'language' => 'fr',
'fid' => '42',
'name' => 'profile_love_migrations',
],
];
return $test;
}
}

View file

@ -62,14 +62,14 @@ class ConfigEntityMapperTest extends UnitTestCase {
->with('entity.configurable_language.edit_form')
->will($this->returnValue(new Route('/admin/config/regional/language/edit/{configurable_language}')));
$definition = array(
$definition = [
'class' => '\Drupal\config_translation\ConfigEntityMapper',
'base_route_name' => 'entity.configurable_language.edit_form',
'title' => '@label language',
'names' => array(),
'names' => [],
'entity_type' => 'configurable_language',
'route_name' => 'config_translation.item.overview.entity.configurable_language.edit_form',
);
];
$typed_config_manager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
@ -152,7 +152,7 @@ class ConfigEntityMapperTest extends UnitTestCase {
$result = $this->configEntityMapper->getOverviewRouteParameters();
$this->assertSame(array('configurable_language' => 'entity_id'), $result);
$this->assertSame(['configurable_language' => 'entity_id'], $result);
}
/**
@ -205,12 +205,12 @@ class ConfigEntityMapperTest extends UnitTestCase {
public function testGetOperations() {
$result = $this->configEntityMapper->getOperations();
$expected = array(
'list' => array(
$expected = [
'list' => [
'title' => 'List',
'url' => Url::fromRoute('config_translation.entity_list', ['mapper_id' => 'configurable_language']),
),
);
],
];
$this->assertEquals($expected, $result);
}

View file

@ -42,13 +42,13 @@ class ConfigFieldMapperTest extends UnitTestCase {
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$this->entity = $this->getMock('Drupal\field\FieldConfigInterface');
$definition = array(
$definition = [
'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_route_name' => 'entity.field_config.node_field_edit_form',
'title' => '@label field',
'names' => array(),
'names' => [],
'entity_type' => 'field_config',
);
];
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
->disableOriginalConstructor()

View file

@ -31,7 +31,7 @@ class ConfigMapperManagerTest extends UnitTestCase {
protected $typedConfigManager;
protected function setUp() {
$language = new Language(array('id' => 'en'));
$language = new Language(['id' => 'en']);
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$language_manager->expects($this->once())
->method('getCurrentLanguage')
@ -83,50 +83,50 @@ class ConfigMapperManagerTest extends UnitTestCase {
* ConfigMapperManager::hasTranslatable() as the second key.
*/
public function providerTestHasTranslatable() {
return array(
array($this->getElement(array()), FALSE),
array($this->getElement(array('aaa' => 'bbb')), FALSE),
array($this->getElement(array('translatable' => FALSE)), FALSE),
array($this->getElement(array('translatable' => TRUE)), TRUE),
array($this->getNestedElement(array(
$this->getElement(array()),
)), FALSE),
array($this->getNestedElement(array(
$this->getElement(array('translatable' => TRUE)),
)), TRUE),
array($this->getNestedElement(array(
$this->getElement(array('aaa' => 'bbb')),
$this->getElement(array('ccc' => 'ddd')),
$this->getElement(array('eee' => 'fff')),
)), FALSE),
array($this->getNestedElement(array(
$this->getElement(array('aaa' => 'bbb')),
$this->getElement(array('ccc' => 'ddd')),
$this->getElement(array('translatable' => TRUE)),
)), TRUE),
array($this->getNestedElement(array(
$this->getElement(array('aaa' => 'bbb')),
$this->getNestedElement(array(
$this->getElement(array('ccc' => 'ddd')),
$this->getElement(array('eee' => 'fff')),
)),
$this->getNestedElement(array(
$this->getElement(array('ggg' => 'hhh')),
$this->getElement(array('iii' => 'jjj')),
)),
)), FALSE),
array($this->getNestedElement(array(
$this->getElement(array('aaa' => 'bbb')),
$this->getNestedElement(array(
$this->getElement(array('ccc' => 'ddd')),
$this->getElement(array('eee' => 'fff')),
)),
$this->getNestedElement(array(
$this->getElement(array('ggg' => 'hhh')),
$this->getElement(array('translatable' => TRUE)),
)),
)), TRUE),
);
return [
[$this->getElement([]), FALSE],
[$this->getElement(['aaa' => 'bbb']), FALSE],
[$this->getElement(['translatable' => FALSE]), FALSE],
[$this->getElement(['translatable' => TRUE]), TRUE],
[$this->getNestedElement([
$this->getElement([]),
]), FALSE],
[$this->getNestedElement([
$this->getElement(['translatable' => TRUE]),
]), TRUE],
[$this->getNestedElement([
$this->getElement(['aaa' => 'bbb']),
$this->getElement(['ccc' => 'ddd']),
$this->getElement(['eee' => 'fff']),
]), FALSE],
[$this->getNestedElement([
$this->getElement(['aaa' => 'bbb']),
$this->getElement(['ccc' => 'ddd']),
$this->getElement(['translatable' => TRUE]),
]), TRUE],
[$this->getNestedElement([
$this->getElement(['aaa' => 'bbb']),
$this->getNestedElement([
$this->getElement(['ccc' => 'ddd']),
$this->getElement(['eee' => 'fff']),
]),
$this->getNestedElement([
$this->getElement(['ggg' => 'hhh']),
$this->getElement(['iii' => 'jjj']),
]),
]), FALSE],
[$this->getNestedElement([
$this->getElement(['aaa' => 'bbb']),
$this->getNestedElement([
$this->getElement(['ccc' => 'ddd']),
$this->getElement(['eee' => 'fff']),
]),
$this->getNestedElement([
$this->getElement(['ggg' => 'hhh']),
$this->getElement(['translatable' => TRUE]),
]),
]), TRUE],
];
}
/**

View file

@ -91,13 +91,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
protected function setUp() {
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
$this->pluginDefinition = array(
$this->pluginDefinition = [
'class' => '\Drupal\config_translation\ConfigNamesMapper',
'base_route_name' => 'system.site_information_settings',
'title' => 'System information',
'names' => array('system.site'),
'names' => ['system.site'],
'weight' => 42,
);
];
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
@ -156,7 +156,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetBaseRouteParameters() {
$result = $this->configNamesMapper->getBaseRouteParameters();
$this->assertSame(array(), $result);
$this->assertSame([], $result);
}
/**
@ -193,7 +193,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetOverviewRouteParameters() {
$result = $this->configNamesMapper->getOverviewRouteParameters();
$this->assertSame(array(), $result);
$this->assertSame([], $result);
}
/**
@ -201,13 +201,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetOverviewRoute() {
$expected = new Route('/admin/config/system/site-information/translate',
array(
[
'_controller' => '\Drupal\config_translation\Controller\ConfigTranslationController::itemPage',
'plugin_id' => 'system.site_information_settings',
),
array(
],
[
'_config_translation_overview_access' => 'TRUE',
)
]
);
$result = $this->configNamesMapper->getOverviewRoute();
$this->assertSame(serialize($expected), serialize($result));
@ -242,7 +242,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
$this->configNamesMapper->populateFromRouteMatch($route_match);
$expected = array('langcode' => 'xx');
$expected = ['langcode' => 'xx'];
$result = $this->configNamesMapper->getAddRouteParameters();
$this->assertSame($expected, $result);
}
@ -252,13 +252,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetAddRoute() {
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/add',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationAddForm',
'plugin_id' => 'system.site_information_settings',
),
array(
],
[
'_config_translation_form_access' => 'TRUE',
)
]
);
$result = $this->configNamesMapper->getAddRoute();
$this->assertSame(serialize($expected), serialize($result));
@ -280,7 +280,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
$this->configNamesMapper->populateFromRouteMatch($route_match);
$expected = array('langcode' => 'xx');
$expected = ['langcode' => 'xx'];
$result = $this->configNamesMapper->getEditRouteParameters();
$this->assertSame($expected, $result);
}
@ -290,13 +290,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetEditRoute() {
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/edit',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationEditForm',
'plugin_id' => 'system.site_information_settings',
),
array(
],
[
'_config_translation_form_access' => 'TRUE',
)
]
);
$result = $this->configNamesMapper->getEditRoute();
$this->assertSame(serialize($expected), serialize($result));
@ -318,7 +318,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
$this->configNamesMapper->populateFromRouteMatch($route_match);
$expected = array('langcode' => 'xx'); $result = $this->configNamesMapper->getDeleteRouteParameters();
$expected = ['langcode' => 'xx']; $result = $this->configNamesMapper->getDeleteRouteParameters();
$this->assertSame($expected, $result);
}
@ -327,13 +327,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function testGetDeleteRoute() {
$expected = new Route('/admin/config/system/site-information/translate/{langcode}/delete',
array(
[
'_form' => '\Drupal\config_translation\Form\ConfigTranslationDeleteForm',
'plugin_id' => 'system.site_information_settings',
),
array(
],
[
'_config_translation_form_access' => 'TRUE',
)
]
);
$result = $this->configNamesMapper->getDeleteRoute();
$this->assertSame(serialize($expected), serialize($result));
@ -403,38 +403,38 @@ class ConfigNamesMapperTest extends UnitTestCase {
public function testGetLangcode() {
// Test that the getLangcode() falls back to 'en', if no explicit language
// code is provided.
$config_factory = $this->getConfigFactoryStub(array(
'system.site' => array('key' => 'value'),
));
$config_factory = $this->getConfigFactoryStub([
'system.site' => ['key' => 'value'],
]);
$this->configNamesMapper->setConfigFactory($config_factory);
$result = $this->configNamesMapper->getLangcode();
$this->assertSame('en', $result);
// Test that getLangcode picks up the language code provided by the
// configuration.
$config_factory = $this->getConfigFactoryStub(array(
'system.site' => array('langcode' => 'xx'),
));
$config_factory = $this->getConfigFactoryStub([
'system.site' => ['langcode' => 'xx'],
]);
$this->configNamesMapper->setConfigFactory($config_factory);
$result = $this->configNamesMapper->getLangcode();
$this->assertSame('xx', $result);
// Test that getLangcode() works for multiple configuration names.
$this->configNamesMapper->addConfigName('system.maintenance');
$config_factory = $this->getConfigFactoryStub(array(
'system.site' => array('langcode' => 'xx'),
'system.maintenance' => array('langcode' => 'xx'),
));
$config_factory = $this->getConfigFactoryStub([
'system.site' => ['langcode' => 'xx'],
'system.maintenance' => ['langcode' => 'xx'],
]);
$this->configNamesMapper->setConfigFactory($config_factory);
$result = $this->configNamesMapper->getLangcode();
$this->assertSame('xx', $result);
// Test that getLangcode() throws an exception when different language codes
// are given.
$config_factory = $this->getConfigFactoryStub(array(
'system.site' => array('langcode' => 'xx'),
'system.maintenance' => array('langcode' => 'yy'),
));
$config_factory = $this->getConfigFactoryStub([
'system.site' => ['langcode' => 'xx'],
'system.maintenance' => ['langcode' => 'yy'],
]);
$this->configNamesMapper->setConfigFactory($config_factory);
try {
$this->configNamesMapper->getLangcode();
@ -448,22 +448,22 @@ class ConfigNamesMapperTest extends UnitTestCase {
* Tests ConfigNamesMapper::getConfigData().
*/
public function testGetConfigData() {
$configs = array(
'system.site' => array(
$configs = [
'system.site' => [
'name' => 'Drupal',
'slogan' => 'Come for the software, stay for the community!',
),
'system.maintenance' => array(
],
'system.maintenance' => [
'enabled' => FALSE,
'message' => '@site is currently under maintenance.',
),
'system.rss' => array(
'items' => array(
],
'system.rss' => [
'items' => [
'limit' => 10,
'view_mode' => 'rss',
),
),
);
],
],
];
$this->configNamesMapper->setConfigNames(array_keys($configs));
$config_factory = $this->getConfigFactoryStub($configs);
@ -489,9 +489,9 @@ class ConfigNamesMapperTest extends UnitTestCase {
$config_names = range(1, count($mock_return_values));
$this->configNamesMapper->setConfigNames($config_names);
$map = array();
$map = [];
foreach ($config_names as $i => $config_name) {
$map[] = array($config_name, $mock_return_values[$i]);
$map[] = [$config_name, $mock_return_values[$i]];
}
$this->typedConfigManager
->expects($this->any())
@ -512,12 +512,12 @@ class ConfigNamesMapperTest extends UnitTestCase {
* ConfigNamesMapper::hasSchema() as the second value.
*/
public function providerTestHasSchema() {
return array(
array(array(TRUE), TRUE),
array(array(FALSE), FALSE),
array(array(TRUE, TRUE, TRUE), TRUE),
array(array(TRUE, FALSE, TRUE), FALSE),
);
return [
[[TRUE], TRUE],
[[FALSE], FALSE],
[[TRUE, TRUE, TRUE], TRUE],
[[TRUE, FALSE, TRUE], FALSE],
];
}
/**
@ -536,9 +536,9 @@ class ConfigNamesMapperTest extends UnitTestCase {
$config_names = range(1, count($mock_return_values));
$this->configNamesMapper->setConfigNames($config_names);
$map = array();
$map = [];
foreach ($config_names as $i => $config_name) {
$map[] = isset($mock_return_values[$i]) ? array($config_name, $mock_return_values[$i]) : array();
$map[] = isset($mock_return_values[$i]) ? [$config_name, $mock_return_values[$i]] : [];
}
$this->configMapperManager
->expects($this->any())
@ -559,14 +559,14 @@ class ConfigNamesMapperTest extends UnitTestCase {
* ConfigNamesMapper::hasTranslatable() as the second value.
*/
public function providerTestHasTranslatable() {
return array(
array(array(), FALSE),
array(array(TRUE), TRUE),
array(array(FALSE), FALSE),
array(array(TRUE, TRUE, TRUE), TRUE),
array(array(FALSE, FALSE, FALSE), FALSE),
array(array(TRUE, FALSE, TRUE), TRUE),
);
return [
[[], FALSE],
[[TRUE], TRUE],
[[FALSE], FALSE],
[[TRUE, TRUE, TRUE], TRUE],
[[FALSE, FALSE, FALSE], FALSE],
[[TRUE, FALSE, TRUE], TRUE],
];
}
/**
@ -587,9 +587,9 @@ class ConfigNamesMapperTest extends UnitTestCase {
$config_names = range(1, count($mock_return_values));
$this->configNamesMapper->setConfigNames($config_names);
$map = array();
$map = [];
foreach ($config_names as $i => $config_name) {
$map[] = array($config_name, $language->getId(), $mock_return_values[$i]);
$map[] = [$config_name, $language->getId(), $mock_return_values[$i]];
}
$this->localeConfigManager
->expects($this->any())
@ -610,13 +610,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
* ConfigNamesMapper::hasTranslation() as the second value.
*/
public function providerTestHasTranslation() {
return array(
array(array(TRUE), TRUE),
array(array(FALSE), FALSE),
array(array(TRUE, TRUE, TRUE), TRUE),
array(array(FALSE, FALSE, TRUE), TRUE),
array(array(FALSE, FALSE, FALSE), FALSE),
);
return [
[[TRUE], TRUE],
[[FALSE], FALSE],
[[TRUE, TRUE, TRUE], TRUE],
[[FALSE, FALSE, TRUE], TRUE],
[[FALSE, FALSE, FALSE], FALSE],
];
}
/**
@ -631,12 +631,12 @@ class ConfigNamesMapperTest extends UnitTestCase {
* Tests ConfigNamesMapper::hasTranslation().
*/
public function testGetOperations() {
$expected = array(
'translate' => array(
$expected = [
'translate' => [
'title' => 'Translate',
'url' => Url::fromRoute('config_translation.item.overview.system.site_information_settings'),
),
);
],
];
$result = $this->configNamesMapper->getOperations();
$this->assertEquals($expected, $result);
}