Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -1,4 +1,3 @@
|
|||
config_translation.contextual_links:
|
||||
title: 'Translate @type_name'
|
||||
deriver: 'Drupal\config_translation\Plugin\Derivative\ConfigTranslationContextualLinks'
|
||||
weight: 100
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
config_translation.local_tasks:
|
||||
title: 'Translate @type_name'
|
||||
deriver: 'Drupal\config_translation\Plugin\Derivative\ConfigTranslationLocalTasks'
|
||||
weight: 100
|
||||
|
|
|
@ -188,6 +188,7 @@ function config_translation_config_schema_info_alter(&$definitions) {
|
|||
'text_format' => '\Drupal\config_translation\FormElement\TextFormat',
|
||||
'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
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
namespace Drupal\config_translation;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
|
@ -43,7 +43,7 @@ class ConfigEntityMapper extends ConfigNamesMapper {
|
|||
/**
|
||||
* Loaded entity instance to help produce the translation interface.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityInterface
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
|
@ -125,13 +125,13 @@ class ConfigEntityMapper extends ConfigNamesMapper {
|
|||
* configuration names to use to check permissions or display a translation
|
||||
* screen.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to set.
|
||||
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
|
||||
* The configuration entity to set.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE, if the entity was set successfully; FALSE otherwise.
|
||||
*/
|
||||
public function setEntity(EntityInterface $entity) {
|
||||
public function setEntity(ConfigEntityInterface $entity) {
|
||||
if (isset($this->entity)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -143,6 +143,7 @@ class ConfigEntityMapper extends ConfigNamesMapper {
|
|||
// page with more names if form altering added more configuration to an
|
||||
// entity. This is not a Drupal 8 best practice (ideally the configuration
|
||||
// would have pluggable components), but this may happen as well.
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */
|
||||
$entity_type_info = $this->entityManager->getDefinition($this->entityType);
|
||||
$this->addConfigName($entity_type_info->getConfigPrefix() . '.' . $entity->id());
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\config_translation;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Configuration mapper for fields.
|
||||
*
|
||||
|
@ -49,4 +51,22 @@ class ConfigFieldMapper extends ConfigEntityMapper {
|
|||
return $this->t('@label fields', array('@label' => $base_entity_info->getLabel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEntity(ConfigEntityInterface $entity) {
|
||||
if (parent::setEntity($entity)) {
|
||||
|
||||
// Field storage config can also contain translatable values. Add the name
|
||||
// of the config as well to the list of configs for this entity.
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
|
||||
$field_storage = $this->entity->getFieldStorageDefinition();
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */
|
||||
$entity_type_info = $this->entityManager->getDefinition($field_storage->getEntityTypeId());
|
||||
$this->addConfigName($entity_type_info->getConfigPrefix() . '.' . $field_storage->id());
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\config_translation;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
|
@ -134,7 +133,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
|
|||
parent::processDefinition($definition, $plugin_id);
|
||||
|
||||
if (!isset($definition['base_route_name'])) {
|
||||
throw new InvalidPluginDefinitionException($plugin_id, SafeMarkup::format("The plugin definition of the mapper '%plugin_id' does not contain a base_route_name.", array('%plugin_id' => $plugin_id)));
|
||||
throw new InvalidPluginDefinitionException($plugin_id, "The plugin definition of the mapper '$plugin_id' does not contain a base_route_name.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ class ConfigTranslationEntityListBuilder extends ConfigEntityListBuilder impleme
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOperations(EntityInterface $entity) {
|
||||
$operations = parent::getDefaultOperations($entity);
|
||||
public function getOperations(EntityInterface $entity) {
|
||||
$operations = parent::getOperations($entity);
|
||||
foreach (array_keys($operations) as $operation) {
|
||||
// This is a translation UI for translators. Show the translation
|
||||
// operation only.
|
||||
|
|
|
@ -91,7 +91,6 @@ abstract class FormElementBase implements ElementInterface {
|
|||
* A render array for the source value.
|
||||
*/
|
||||
protected function getSourceElement(LanguageInterface $source_language, $source_config) {
|
||||
// @todo Should support singular+plurals https://www.drupal.org/node/2454829
|
||||
if ($source_config) {
|
||||
$value = '<span lang="' . $source_language->getId() . '">' . nl2br($source_config) . '</span>';
|
||||
}
|
||||
|
@ -162,7 +161,6 @@ abstract class FormElementBase implements ElementInterface {
|
|||
*/
|
||||
protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
|
||||
// Add basic properties that apply to all form elements.
|
||||
// @todo Should support singular+plurals https://www.drupal.org/node/2454829
|
||||
return array(
|
||||
'#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array(
|
||||
'!label' => $this->t($this->definition['label']),
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_translation\FormElement\PluralVariants.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_translation\FormElement;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Config\LanguageConfigOverride;
|
||||
|
||||
/**
|
||||
* Defines form elements for plurals in configuration translation.
|
||||
*/
|
||||
class PluralVariants extends FormElementBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSourceElement(LanguageInterface $source_language, $source_config) {
|
||||
$plurals = $this->getNumberOfPlurals($source_language->getId());
|
||||
$values = explode(LOCALE_PLURAL_DELIMITER, $source_config);
|
||||
$element = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@source_language)</span>', array(
|
||||
'@label' => $this->t($this->definition->getLabel()),
|
||||
'@source_language' => $source_language->getName(),
|
||||
)),
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
for ($i = 0; $i < $plurals; $i++) {
|
||||
$element[$i] = array(
|
||||
'#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(
|
||||
'@langcode' => $source_language->getId(),
|
||||
'@value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'),
|
||||
)),
|
||||
);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => SafeMarkup::format('@label <span class="visually-hidden">(@translation_language)</span>', array(
|
||||
'@label' => $this->t($this->definition->getLabel()),
|
||||
'@translation_language' => $translation_language->getName(),
|
||||
)),
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
for ($i = 0; $i < $plurals; $i++) {
|
||||
$element[$i] = array(
|
||||
'#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()),
|
||||
);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setConfig(Config $base_config, LanguageConfigOverride $config_translation, $config_values, $base_key = NULL) {
|
||||
$config_values = implode(LOCALE_PLURAL_DELIMITER, $config_values);
|
||||
parent::setConfig($base_config, $config_translation, $config_values, $base_key);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,11 +9,13 @@ namespace Drupal\config_translation\Plugin\Menu\ContextualLink;
|
|||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Menu\ContextualLinkDefault;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Defines a contextual link plugin with a dynamic title.
|
||||
*/
|
||||
class ConfigTranslationContextualLink extends ContextualLinkDefault {
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The mapper plugin discovery service.
|
||||
|
@ -26,17 +28,12 @@ class ConfigTranslationContextualLink extends ContextualLinkDefault {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTitle() {
|
||||
$options = array();
|
||||
if (!empty($this->pluginDefinition['title_context'])) {
|
||||
$options['context'] = $this->pluginDefinition['title_context'];
|
||||
}
|
||||
|
||||
// Take custom 'config_translation_plugin_id' plugin definition key to
|
||||
// retrieve title. We need to retrieve a runtime title (as opposed to
|
||||
// storing the title on the plugin definition for the link) because
|
||||
// it contains translated parts that we need in the runtime language.
|
||||
// Use the custom 'config_translation_plugin_id' plugin definition key to
|
||||
// retrieve the title. We need to retrieve a runtime title (as opposed to
|
||||
// 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($this->pluginDefinition['title'], array('@type_name' => $type_name), $options);
|
||||
return $this->t('Translate @type_name', array('@type_name' => $type_name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,11 +9,13 @@ namespace Drupal\config_translation\Plugin\Menu\LocalTask;
|
|||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Menu\LocalTaskDefault;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Defines a local task plugin with a dynamic title.
|
||||
*/
|
||||
class ConfigTranslationLocalTask extends LocalTaskDefault {
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The mapper plugin discovery service.
|
||||
|
@ -26,17 +28,12 @@ class ConfigTranslationLocalTask extends LocalTaskDefault {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTitle() {
|
||||
$options = array();
|
||||
if (!empty($this->pluginDefinition['title_context'])) {
|
||||
$options['context'] = $this->pluginDefinition['title_context'];
|
||||
}
|
||||
|
||||
// Take custom 'config_translation_plugin_id' plugin definition key to
|
||||
// retrieve title. We need to retrieve a runtime title (as opposed to
|
||||
// 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($this->pluginDefinition['title'], array('@type_name' => $type_name), $options);
|
||||
return $this->t('Translate @type_name', array('@type_name' => $type_name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,16 @@ class ConfigTranslationOverviewTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('contact', 'config_translation', 'views', 'views_ui', 'contextual', 'config_test', 'config_translation_test');
|
||||
public static $modules = [
|
||||
'config_test',
|
||||
'config_translation',
|
||||
'config_translation_test',
|
||||
'contact',
|
||||
'contextual',
|
||||
'entity_test_operation',
|
||||
'views',
|
||||
'views_ui',
|
||||
];
|
||||
|
||||
/**
|
||||
* Languages to enable.
|
||||
|
@ -67,6 +76,14 @@ class ConfigTranslationOverviewTest extends WebTestBase {
|
|||
$this->drupalGet('admin/config/regional/config-translation');
|
||||
$this->assertLinkByHref('admin/config/regional/config-translation/config_test');
|
||||
$this->assertLinkByHref('admin/config/people/accounts/translate');
|
||||
// Make sure there is only a single operation for each dropbutton, either
|
||||
// 'List' or 'Translate'.
|
||||
foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
|
||||
$this->assertIdentical(1, $dropbutton->count());
|
||||
foreach ($dropbutton->li as $link) {
|
||||
$this->assertTrue(((string) $link->a === 'Translate') || ((string) $link->a === 'List'));
|
||||
}
|
||||
}
|
||||
|
||||
$labels = array(
|
||||
'&$nxd~i0',
|
||||
|
@ -86,6 +103,15 @@ class ConfigTranslationOverviewTest extends WebTestBase {
|
|||
$this->assertLinkByHref($base_url . '/translate');
|
||||
$this->assertText(SafeMarkup::checkPlain($test_entity->label()));
|
||||
|
||||
// Make sure there is only a single 'Translate' operation for each
|
||||
// dropbutton.
|
||||
foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
|
||||
$this->assertIdentical(1, $dropbutton->count());
|
||||
foreach ($dropbutton->li as $link) {
|
||||
$this->assertIdentical('Translate', (string) $link->a);
|
||||
}
|
||||
}
|
||||
|
||||
$entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
|
||||
$this->drupalGet($base_url . '/translate');
|
||||
|
||||
|
@ -127,6 +153,8 @@ class ConfigTranslationOverviewTest extends WebTestBase {
|
|||
$original_label = 'Default';
|
||||
$overridden_label = 'Overridden label';
|
||||
|
||||
$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(
|
||||
'value' => $overridden_label,
|
||||
|
@ -135,7 +163,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
|
|||
$this->writeSettings($settings);
|
||||
|
||||
// Test that the overridden label is loaded with the entity.
|
||||
$this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label);
|
||||
$this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
|
||||
|
||||
// Test that the original label on the listing page is intact.
|
||||
$this->drupalGet('admin/config/regional/config-translation/config_test');
|
||||
|
|
|
@ -13,6 +13,8 @@ use Drupal\Component\Utility\Unicode;
|
|||
use Drupal\Core\Config\FileStorage;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
@ -28,7 +30,21 @@ class ConfigTranslationUiTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'contact', 'contact_test', 'config_translation', 'config_translation_test', 'views', 'views_ui', 'contextual', 'filter', 'filter_test');
|
||||
public static $modules = [
|
||||
'config_translation',
|
||||
'config_translation_test',
|
||||
'contact',
|
||||
'contact_test',
|
||||
'contextual',
|
||||
'entity_test',
|
||||
'field_test',
|
||||
'field_ui',
|
||||
'filter',
|
||||
'filter_test',
|
||||
'node',
|
||||
'views',
|
||||
'views_ui',
|
||||
];
|
||||
|
||||
/**
|
||||
* Languages to enable.
|
||||
|
@ -89,6 +105,7 @@ class ConfigTranslationUiTest extends WebTestBase {
|
|||
'administer themes',
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'translate interface',
|
||||
]
|
||||
);
|
||||
// Create and login user.
|
||||
|
@ -609,6 +626,136 @@ class ConfigTranslationUiTest extends WebTestBase {
|
|||
$this->assertFieldByName('translation[config_names][views.view.frontpage][display][default][display_options][title]', $display_options_master . " FR");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the number of source elements for plural strings in config translation forms.
|
||||
*/
|
||||
public function testPluralConfigStringsSourceElements() {
|
||||
$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)),
|
||||
);
|
||||
|
||||
foreach ($languages as $langcode => $data) {
|
||||
// Import a .po file to add a new language with a given number of plural forms
|
||||
$name = tempnam('temporary://', $langcode . '_') . '.po';
|
||||
file_put_contents($name, $this->getPoFile($data['plurals']));
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', array(
|
||||
'langcode' => $langcode,
|
||||
'files[file]' => $name,
|
||||
), t('Import'));
|
||||
|
||||
// Change the config langcode of the 'files' view.
|
||||
$config = \Drupal::service('config.factory')->getEditable('views.view.files');
|
||||
$config->set('langcode', $langcode);
|
||||
$config->save();
|
||||
|
||||
// Go to the translation page of the 'files' view.
|
||||
$translation_url = 'admin/structure/views/view/files/translate/' . $langcode . '/add';
|
||||
$this->drupalGet($translation_url);
|
||||
|
||||
// Check if the expected number of source elements are present.
|
||||
foreach ($data['expected'] as $index => $expected) {
|
||||
if ($expected) {
|
||||
$this->assertRaw('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
|
||||
}
|
||||
else {
|
||||
$this->assertNoRaw('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test translation of plural strings with multiple plural forms in config.
|
||||
*/
|
||||
public function testPluralConfigStrings() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// First import a .po file with multiple plural forms.
|
||||
// This will also automatically add the 'sl' language.
|
||||
$name = tempnam('temporary://', "sl_") . '.po';
|
||||
file_put_contents($name, $this->getPoFile(4));
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', array(
|
||||
'langcode' => 'sl',
|
||||
'files[file]' => $name,
|
||||
), t('Import'));
|
||||
|
||||
// Translate the files view, as this one uses numeric formatters.
|
||||
$description = 'Singular form';
|
||||
$field_value = '1 place';
|
||||
$field_value_plural = '@count places';
|
||||
$translation_url = 'admin/structure/views/view/files/translate/sl/add';
|
||||
$this->drupalGet($translation_url);
|
||||
|
||||
// Make sure original text is present on this page, in addition to 2 new
|
||||
// empty fields.
|
||||
$this->assertRaw($description);
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', $field_value);
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', $field_value_plural);
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', '');
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', '');
|
||||
|
||||
// Then make sure it also works.
|
||||
$edit = [
|
||||
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]' => $field_value . ' SL',
|
||||
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]' => $field_value_plural . ' 1 SL',
|
||||
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]' => $field_value_plural . ' 2 SL',
|
||||
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]' => $field_value_plural . ' 3 SL',
|
||||
];
|
||||
$this->drupalPostForm($translation_url, $edit, t('Save translation'));
|
||||
|
||||
// Make sure the values have changed.
|
||||
$this->drupalGet($translation_url);
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', "$field_value SL");
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', "$field_value_plural 1 SL");
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', "$field_value_plural 2 SL");
|
||||
$this->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', "$field_value_plural 3 SL");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the translation of field and field storage configuration.
|
||||
*/
|
||||
public function testFieldConfigTranslation() {
|
||||
// Add a test field which has a translatable field setting and a
|
||||
// translatable field storage setting.
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_field',
|
||||
]);
|
||||
|
||||
$translatable_storage_setting = $this->randomString();
|
||||
$field_storage->setSetting('translatable_storage_setting', $translatable_storage_setting);
|
||||
$field_storage->save();
|
||||
|
||||
$bundle = strtolower($this->randomMachineName());
|
||||
entity_test_create_bundle($bundle);
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => $bundle,
|
||||
]);
|
||||
|
||||
$translatable_field_setting = $this->randomString();
|
||||
$field->setSetting('translatable_field_setting', $translatable_field_setting);
|
||||
$field->save();
|
||||
|
||||
$this->drupalLogin($this->translatorUser);
|
||||
|
||||
$this->drupalGet("/entity_test/structure/$bundle/fields/entity_test.$bundle.$field_name/translate");
|
||||
$this->clickLink('Add');
|
||||
|
||||
$this->assertText('Translatable field setting');
|
||||
$this->assertRaw(SafeMarkup::checkPlain($translatable_field_setting));
|
||||
$this->assertText('Translatable storage setting');
|
||||
$this->assertRaw(SafeMarkup::checkPlain($translatable_storage_setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test translation storage in locale storage.
|
||||
*/
|
||||
|
@ -936,4 +1083,43 @@ class ConfigTranslationUiTest extends WebTestBase {
|
|||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns a .po file with a given number of plural forms.
|
||||
*/
|
||||
public function getPoFile($plurals) {
|
||||
$po_file = array();
|
||||
|
||||
$po_file[1] = <<< EOF
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 8\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\\n"
|
||||
EOF;
|
||||
|
||||
$po_file[2] = <<< EOF
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 8\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n>1);\\n"
|
||||
EOF;
|
||||
|
||||
$po_file[4] = <<< EOF
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 8\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=4; plural=(((n%100)==1)?(0):(((n%100)==2)?(1):((((n%100)==3)||((n%100)==4))?(2):3)));\\n"
|
||||
EOF;
|
||||
|
||||
return $po_file[$plurals];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$this->entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
|
||||
$this->entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
|
||||
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
|
||||
|
||||
|
@ -109,6 +109,10 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
->will($this->returnValue('entity_id'));
|
||||
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type
|
||||
->expects($this->any())
|
||||
->method('getConfigPrefix')
|
||||
->will($this->returnValue('config_prefix'));
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getDefinition')
|
||||
|
@ -118,6 +122,10 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
$result = $this->configEntityMapper->setEntity($this->entity);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// Ensure that the configuration name was added to the mapper.
|
||||
$plugin_definition = $this->configEntityMapper->getPluginDefinition();
|
||||
$this->assertTrue(in_array('config_prefix.entity_id', $plugin_definition['names']));
|
||||
|
||||
// Make sure setEntity() returns FALSE when called a second time.
|
||||
$result = $this->configEntityMapper->setEntity($this->entity);
|
||||
$this->assertFalse($result);
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\config_translation\Unit;
|
||||
|
||||
use Drupal\config_translation\ConfigFieldMapper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the functionality provided by the configuration field mapper.
|
||||
*
|
||||
* @group config_translation
|
||||
*
|
||||
* @coversDefaultClass \Drupal\config_translation\ConfigFieldMapper
|
||||
*/
|
||||
class ConfigFieldMapperTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The configuration field mapper to test.
|
||||
*
|
||||
* @var \Drupal\config_translation\ConfigFieldMapper
|
||||
*/
|
||||
protected $configFieldMapper;
|
||||
|
||||
/**
|
||||
* The field config instance used for testing.
|
||||
*
|
||||
* @var \Drupal\field\FieldConfigInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entity = $this->getMock('Drupal\field\FieldConfigInterface');
|
||||
|
||||
$definition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigFieldMapper',
|
||||
'base_route_name' => 'entity.field_config.node_field_edit_form',
|
||||
'title' => '!label field',
|
||||
'names' => array(),
|
||||
'entity_type' => 'field_config',
|
||||
);
|
||||
|
||||
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->configFieldMapper = new ConfigFieldMapper(
|
||||
'node_fields',
|
||||
$definition,
|
||||
$this->getConfigFactoryStub(),
|
||||
$this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'),
|
||||
$locale_config_manager,
|
||||
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
|
||||
$this->getMock('Drupal\Core\Routing\RouteProviderInterface'),
|
||||
$this->getStringTranslationStub(),
|
||||
$this->entityManager,
|
||||
$this->getMock('Drupal\Core\Language\LanguageManagerInterface')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigFieldMapper::setEntity().
|
||||
*
|
||||
* @covers ::setEntity
|
||||
*/
|
||||
public function testSetEntity() {
|
||||
$entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
$entity_type
|
||||
->expects($this->any())
|
||||
->method('getConfigPrefix')
|
||||
->will($this->returnValue('config_prefix'));
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
$field_storage = $this->getMock('Drupal\field\FieldStorageConfigInterface');
|
||||
$field_storage
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue('field_storage_id'));
|
||||
|
||||
$this->entity
|
||||
->expects($this->any())
|
||||
->method('getFieldStorageDefinition')
|
||||
->will($this->returnValue($field_storage));
|
||||
|
||||
$result = $this->configFieldMapper->setEntity($this->entity);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// Ensure that the configuration name was added to the mapper.
|
||||
$plugin_definition = $this->configFieldMapper->getPluginDefinition();
|
||||
$this->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names']));
|
||||
|
||||
// Make sure setEntity() returns FALSE when called a second time.
|
||||
$result = $this->configFieldMapper->setEntity($this->entity);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue