updated core to 8.6.3

This commit is contained in:
2018-11-21 12:49:46 +01:00
parent 8ca34853a3
commit c92c348eee
521 changed files with 12199 additions and 4578 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ function hook_field_widget_multivalue_WIDGET_TYPE_form_alter(array &$elements, \
// Code here will only act on widgets of type WIDGET_TYPE. For example,
// hook_field_widget_multivalue_mymodule_autocomplete_form_alter() will only
// act on widgets of type 'mymodule_autocomplete'.
// Change the autcomplete route for each autocomplete element within the
// Change the autocomplete route for each autocomplete element within the
// multivalue widget.
foreach (Element::children($elements) as $delta => $element) {
$elements[$delta]['#autocomplete_route_name'] = 'mymodule.autocomplete_route';
@@ -0,0 +1,53 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the settings property and translation for boolean fields.
*
* @MigrateProcessPlugin(
* id = "d6_field_instance_option_translation",
* handle_multiples = TRUE
* )
*/
class FieldInstanceOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($field_type, $global_settings) = $value;
$option_key = 0;
$translation = '';
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'boolean';
$option = preg_replace('/^option_/', '', $row->getSourceProperty('property'));
for ($i = 0; $i < 2; $i++) {
$value = $list[$i];
$tmp = explode("|", $value);
$original_option_key = isset($tmp[0]) ? $tmp[0] : NULL;
$option_key = ($i === 0) ? 'off_label' : 'on_label';
// Find property with name matching the original option.
if ($option == $original_option_key) {
$translation = $row->getSourceProperty('translation');
break;
}
}
break;
default:
}
}
return ['settings.' . $option_key, $translation];
}
}
@@ -0,0 +1,59 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the allowed values translation for select lists.
*
* @MigrateProcessPlugin(
* id = "d6_field_option_translation",
* handle_multiples = TRUE
* )
*/
class FieldOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Get the field default/mapped settings.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($field_type, $global_settings) = $value;
$allowed_values = '';
$i = 0;
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'list_string':
case 'list_integer':
case 'list_float':
// Remove the prefix used in the i18n_strings table for field options
// to get the option value.
$option = preg_replace('/^option_/', '', $row->getSourceProperty('property'));
$i = 0;
foreach ($list as $allowed_value) {
// Get the key for this allowed value which may be a key|label pair
// or or just key.
$value = explode("|", $allowed_value);
if (isset($value[0]) && ($value[0] == $option)) {
$allowed_values = ['label' => $row->getSourceProperty('translation')];
break;
}
$i++;
}
break;
default:
}
}
return ["settings.allowed_values.$i", $allowed_values];
}
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
/**
* Gets field instance option label translations.
*
* @MigrateSource(
* id = "d6_field_instance_option_translation",
* source_module = "i18ncck"
* )
*/
class FieldInstanceOptionTranslation extends FieldOptionTranslation {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
$query->join('content_node_field_instance', 'cnfi', 'cnf.field_name = cnfi.field_name');
$query->addField('cnfi', 'type_name');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'type_name' => $this->t('Type (article, page, ....)'),
];
return parent::fields() + $fields;
}
}
@@ -0,0 +1,60 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Gets field label and description translations.
*
* @MigrateSource(
* id = "d6_field_instance_label_description_translation",
* source_module = "i18ncck"
* )
*/
class FieldLabelDescriptionTranslation extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
// Get translations for field labels and descriptions.
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n', ['property', 'objectid', 'type'])
->fields('lt', ['lid', 'translation', 'language'])
->condition('i18n.type', 'field')
->isNotNull('language')
->isNotNull('translation');
$condition = $query->orConditionGroup()
->condition('property', 'widget_label')
->condition('property', 'widget_description');
$query->condition($condition);
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'property' => $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['property']['type'] = 'string';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}
@@ -0,0 +1,78 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
/**
* Gets field option label translations.
*
* @MigrateSource(
* id = "d6_field_option_translation",
* source_module = "i18ncck"
* )
*/
class FieldOptionTranslation extends Field {
/**
* {@inheritdoc}
*/
public function query() {
// Get the fields that have field options translations.
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n')
->fields('lt', [
'translation',
'language',
'plid',
'plural',
'i18n_status',
])
->condition('i18n.type', 'field')
->condition('property', 'option\_%', 'LIKE')
->isNotNull('translation');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->leftjoin('content_node_field', 'cnf', 'cnf.field_name = i18n.objectid');
$query->addField('cnf', 'field_name');
$query->addField('cnf', 'global_settings');
// Minimise changes to the d6_field_option_translation.yml, which is copied
// from d6_field.yml, by ensuring the 'type' property is from
// content_node_field table.
$query->addField('cnf', 'type');
$query->addField('i18n', 'type', 'i18n_type');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'property' => $this->t('Option ID.'),
'objectid' => $this->t('Object ID'),
'objectindex' => $this->t('Integer value of Object ID'),
'format' => $this->t('The input format used by this string'),
'lid' => $this->t('Source string ID'),
'language' => $this->t('Language code'),
'translation' => $this->t('Translation of the option'),
'plid' => $this->t('Parent lid'),
'plural' => $this->t('Plural index number in case of plural strings'),
];
return parent::fields() + $fields;
}
/**
* {@inheritdoc}
*/
/**
* {@inheritdoc}
*/
public function getIds() {
return parent::getIds() +
[
'language' => ['type' => 'string'],
'property' => ['type' => 'string'],
];
}
}
@@ -2,63 +2,18 @@
namespace Drupal\field\Tests\EntityReference;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait as nonDeprecatedEntityReferenceTestTrait;
/**
* Provides common functionality for the EntityReference test classes.
*
* @deprecated in Drupal 8.6.2 for removal before 9.0.0. Use
* Drupal\Tests\field\Traits\EntityReferenceTestTrait instead.
*
* @see https://www.drupal.org/node/2998888
*/
trait EntityReferenceTestTrait {
/**
* Creates a field of an entity reference field storage on the specified bundle.
*
* @param string $entity_type
* The type of entity the field will be attached to.
* @param string $bundle
* The bundle name of the entity the field will be attached to.
* @param string $field_name
* The name of the field; if it already exists, a new instance of the existing
* field will be created.
* @param string $field_label
* The label of the field.
* @param string $target_entity_type
* The type of the referenced entity.
* @param string $selection_handler
* The selection handler used by this field.
* @param array $selection_handler_settings
* An array of settings supported by the selection handler specified above.
* (e.g. 'target_bundles', 'sort', 'auto_create', etc).
* @param int $cardinality
* The cardinality of the field.
*
* @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()
*/
protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) {
// Look for or add the specified field to the requested entity bundle.
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
FieldStorageConfig::create([
'field_name' => $field_name,
'type' => 'entity_reference',
'entity_type' => $entity_type,
'cardinality' => $cardinality,
'settings' => [
'target_type' => $target_entity_type,
],
])->save();
}
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'label' => $field_label,
'settings' => [
'handler' => $selection_handler,
'handler_settings' => $selection_handler_settings,
],
])->save();
}
}
use nonDeprecatedEntityReferenceTestTrait;
}
@@ -5,7 +5,7 @@ namespace Drupal\Tests\field\Functional\EntityReference;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\node\Entity\Node;
use Drupal\field\Entity\FieldStorageConfig;
@@ -6,8 +6,8 @@ use Drupal\Component\Render\FormattableMarkup;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\config\Traits\AssertConfigEntityImportTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Tests various Entity reference UI components.
@@ -5,7 +5,7 @@ namespace Drupal\Tests\field\Functional\EntityReference;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Tests possible XSS security issues in entity references.
@@ -31,7 +31,7 @@ class DisplayApiTest extends FieldKernelTestBase {
/**
* The field cardinality to use in this test.
*
* @var number
* @var int
*/
protected $cardinality;
@@ -8,12 +8,12 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Drupal\entity_test\Entity\EntityTestLabel;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Tests the formatters functionality.
@@ -14,7 +14,6 @@ use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestStringId;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
@@ -24,6 +23,7 @@ use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Tests the new entity API for the entity reference field type.
@@ -5,10 +5,10 @@ namespace Drupal\Tests\field\Kernel\EntityReference;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Symfony\Component\Debug\BufferingLogger;
/**
@@ -4,9 +4,9 @@ namespace Drupal\Tests\field\Kernel\EntityReference\Views;
use Drupal\entity_test\Entity\EntityTestMulChanged;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
@@ -331,6 +331,15 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
// Fourth result has no reference from EntityTestMul hence the output for
// should be empty.
$this->assertEqual('', $view->getStyle()->getField(3, 'name_2'));
$fields = $view->field;
// Check getValue for reference with a value. The first 3 rows reference
// EntityTestMul, so have value 'name1'.
$this->assertEquals('name1', $fields['name_2']->getValue($view->result[0]));
$this->assertEquals('name1', $fields['name_2']->getValue($view->result[1]));
$this->assertEquals('name1', $fields['name_2']->getValue($view->result[2]));
// Ensure getValue works on empty references.
$this->assertNull($fields['name_2']->getValue($view->result[3]));
}
}
@@ -0,0 +1,134 @@
<?php
namespace Drupal\Tests\field\Kernel\Migrate\d6;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Core\Database\Database;
use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration field label and description i18n translations.
*
* @group migrate_drupal_6
* @group legacy
*/
class MigrateFieldInstanceLabelDescriptionTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface {
/**
* {@inheritdoc}
*/
public static $modules = [
'config_translation',
'locale',
'language',
'menu_ui',
'node',
'field',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->migrateFields();
$this->installEntitySchema('node');
$this->installConfig(['node']);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
$this->executeMigration('language');
$this->executeMigration('d6_field_instance_label_description_translation');
}
/**
* {@inheritdoc}
*/
public static function migrateDumpAlter(KernelTestBase $test) {
$db = Database::getConnection('default', 'migrate');
// Alter the database to test the migration is successful when a translated
// field is deleted but the translation data for that field remains in both
// the i18n_strings and locales_target tables.
$db->delete('content_node_field_instance')
->condition('field_name', 'field_test')
->condition('type_name', 'story')
->execute();
}
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFieldInstanceLabelDescriptionTranslationMigration() {
$language_manager = $this->container->get('language_manager');
// Tests fields on 'story' node type.
// Check that the deleted field with translations was skipped.
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test');
$this->assertNull($config_translation->get('label'));
$this->assertNull($config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_two');
$this->assertSame("fr - Integer Field", $config_translation->get('label'));
$this->assertSame("fr - An example integer field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_four');
$this->assertSame("fr - Float Field", $config_translation->get('label'));
$this->assertSame("fr - An example float field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_email');
$this->assertSame("fr - Email Field", $config_translation->get('label'));
$this->assertSame("fr - An example email field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_imagefield');
$this->assertSame("fr - Image Field", $config_translation->get('label'));
$this->assertSame("fr - An example image field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_imagefield');
$this->assertSame("zu - Image Field", $config_translation->get('label'));
$this->assertSame("zu - An example image field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_filefield');
$this->assertSame("fr - File Field", $config_translation->get('label'));
$this->assertSame("fr - An example file field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_link');
$this->assertSame("fr - Link Field", $config_translation->get('label'));
$this->assertSame("fr - An example link field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
$this->assertSame("fr - Date Field", $config_translation->get('label'));
$this->assertSame("fr - An example date field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datetime');
$this->assertSame("fr - Datetime Field", $config_translation->get('label'));
$this->assertSame("fr - An example datetime field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datestamp');
$this->assertSame("fr - Date Stamp Field", $config_translation->get('label'));
$this->assertSame("fr - An example date stamp field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
$this->assertSame("fr - Date Field", $config_translation->get('label'));
$this->assertSame("fr - An example date field.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_phone');
$this->assertSame("fr - Phone Field", $config_translation->get('label'));
$this->assertSame("fr - An example phone field.", $config_translation->get('description'));
// Tests fields on 'test_page' node type.
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_page.field_test');
$this->assertSame("Champ de texte", $config_translation->get('label'));
$this->assertSame("fr - An example text field.", $config_translation->get('description'));
// Tests fields on 'test_planet' node type.
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_multivalue');
$this->assertSame("fr - Decimal Field", $config_translation->get('label'));
$this->assertSame("Un exemple plusieurs valeurs champ décimal.", $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_test_text_single_checkbox');
$this->assertNull($config_translation->get('label'));
$this->assertSame('fr - An example text field using a single on/off checkbox.', $config_translation->get('description'));
}
}
@@ -0,0 +1,75 @@
<?php
namespace Drupal\Tests\field\Kernel\Migrate\d6;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Migrate field instance option translations.
*
* @group migrate_drupal_6
*/
class MigrateFieldInstanceOptionTranslationTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules =
[
'config_translation',
'language',
'locale',
'menu_ui',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
$this->executeMigrations([
'language',
'd6_node_type',
'd6_field',
'd6_field_instance',
'd6_field_option_translation',
'd6_field_instance_option_translation',
]);
}
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFieldInstanceOptionTranslation() {
$language_manager = $this->container->get('language_manager');
/** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_float_single_checkbox');
$option_translation = ['on_label' => 'fr - 1.234'];
$this->assertSame($option_translation, $config_translation->get('settings'));
$config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_float_single_checkbox');
$option_translation = ['on_label' => 'zu - 1.234'];
$this->assertSame($option_translation, $config_translation->get('settings'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_text_single_checkbox');
$option_translation = [
'off_label' => 'fr - Hello',
'on_label' => 'fr - Goodbye',
];
$this->assertSame($option_translation, $config_translation->get('settings'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_text_single_checkbox2');
$option_translation = [
'off_label' => 'fr - Off',
'on_label' => 'fr - Hello',
];
$this->assertSame($option_translation, $config_translation->get('settings'));
$config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_text_single_checkbox2');
$option_translation = ['on_label' => 'zu - Hello'];
$this->assertSame($option_translation, $config_translation->get('settings'));
}
}
@@ -0,0 +1,84 @@
<?php
namespace Drupal\Tests\field\Kernel\Migrate\d6;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Migrate field option translations.
*
* @group migrate_drupal_6
*/
class MigrateFieldOptionTranslationTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'config_translation',
'language',
'locale',
'menu_ui',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigrations([
'language',
'd6_field',
'd6_field_option_translation',
]);
}
/**
* Tests the Drupal 6 field to Drupal 8 migration.
*/
public function testFieldOptionTranslation() {
$language_manager = $this->container->get('language_manager');
// Test a select list with allowed values of key only.
/** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_test_integer_selectlist');
$allowed_values = [
1 => [
'label' => 'fr - 2341',
],
3 => [
'label' => 'fr - 4123',
],
];
$this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
$config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.storage.node.field_test_integer_selectlist');
$allowed_values = [
1 => [
'label' => 'zu - 2341',
],
];
$this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
// Test a select list with allowed values of key|label.
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_test_string_selectlist');
$allowed_values = [
0 => [
'label' => 'Noir',
],
];
$this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
$config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.storage.node.field_test_string_selectlist');
$allowed_values = [
0 => [
'label' => 'Okumnyama',
],
1 => [
'label' => 'Mhlophe',
],
];
$this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
}
}
@@ -0,0 +1,79 @@
<?php
namespace Drupal\Tests\field\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the field label and description translation source plugin.
*
* @covers \Drupal\field\Plugin\migrate\source\d6\FieldLabelDescriptionTranslation
* @group migrate_drupal
*/
class FieldInstanceLabelDescriptionTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['config_translation', 'migrate_drupal', 'field'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = [];
// The source data.
$test[0]['source_data'] = [
'i18n_strings' => [
[
'lid' => 10,
'objectid' => 'story-field_test_two',
'type' => 'field',
'property' => 'widget_label',
],
[
'lid' => 11,
'objectid' => 'story-field_test_two',
'type' => 'field',
'property' => 'widget_description',
],
[
'lid' => 12,
'objectid' => 'story-field_test_two',
'type' => 'field',
'property' => 'widget_description',
],
],
'locales_target' => [
[
'lid' => 10,
'translation' => "fr - Integer Field",
'language' => 'fr',
],
[
'lid' => 11,
'translation' => 'fr - An example integer field.',
'language' => 'fr',
],
],
];
$test[0]['expected_results'] = [
[
'property' => 'widget_label',
'translation' => "fr - Integer Field",
'language' => 'fr',
'lid' => '10',
],
[
'property' => 'widget_description',
'translation' => 'fr - An example integer field.',
'language' => 'fr',
'lid' => '11',
],
];
return $test;
}
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\field\Kernel\Plugin\migrate\source\d6;
/**
* Tests the field instance option translation source plugin.
*
* @covers \Drupal\field\Plugin\migrate\source\d6\FieldInstanceOptionTranslation
* @group migrate_drupal
*/
class FieldInstanceOptionTranslationTest extends FieldOptionTranslationTest {
/**
* {@inheritdoc}
*/
public static $modules = ['field', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = parent::providerSource();
// FieldInstanceOptionTranslation extends FieldOptionTranslation so the
// same test can be used with the addition of the 'type' field to the
// output.
$test[0]['expected_results'][0]['type'] = 'text';
$test[0]['expected_results'][1]['type'] = 'text';
$test[0]['expected_results'][2]['type'] = 'number_integer';
$test[0]['expected_results'][3]['type'] = 'number_integer';
return $test;
}
}
@@ -0,0 +1,242 @@
<?php
namespace Drupal\Tests\field\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the field option translation source plugin.
*
* @covers \Drupal\field\Plugin\migrate\source\d6\FieldOptionTranslation
* @group migrate_drupal
*/
class FieldOptionTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['field', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = [];
// The source data.
$test[0]['source_data']['content_node_field'] = [
[
'field_name' => 'field_test_text_single_checkbox',
'type' => 'text',
'global_settings' => 'a:4:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:10:"Off\\nHello";s:18:"allowed_values_php";s:0:"";}',
'required' => 0,
'multiple' => 0,
'db_storage' => 1,
'module' => 'text',
],
[
'field_name' => 'field_test_integer_selectlist',
'type' => 'number_integer',
'global_settings' => 'a:6:{s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:3:"min";s:0:"";s:3:"max";s:0:"";s:14:"allowed_values";s:22:"1234\\n2341\\n3412\\n4123";s:18:"allowed_values_php";s:0:"";}',
'required' => 0,
'multiple' => 0,
'db_storage' => 1,
'module' => 'text',
],
];
$test[0]['source_data']['content_node_field_instance'] = [
[
'field_name' => 'field_test_text_single_checkbox',
'type_name' => 'story',
'weight' => 1,
'label' => 'Text Single Checkbox Field',
'widget_type' => 'optionwidgets_onoff',
'description' => 'An example text field using a single on/off checkbox.',
'widget_module' => 'optionwidgets',
'widget_active' => 1,
'required' => 1,
'active' => 1,
'global_settings' => 'a:0;',
'widget_settings' => 'a:0;',
'display_settings' => 'a:0;',
],
[
'field_name' => 'field_test_integer_selectlist',
'type_name' => 'story',
'weight' => 1,
'label' => 'Integer Select List Field',
'widget_type' => 'optionwidgets_select',
'description' => 'An example integer field using a select list.',
'widget_module' => 'optionwidgets',
'widget_active' => 1,
'required' => 1,
'active' => 1,
'global_settings' => 'a:0;',
'widget_settings' => 'a:0;',
'display_settings' => 'a:0;',
],
];
$test[0]['source_data']['i18n_strings'] = [
[
'lid' => 10,
'objectid' => 'field_test_text_single_checkbox',
'type' => 'field',
'property' => 'option_0',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 11,
'objectid' => 'field_test_text_single_checkbox',
'type' => 'field',
'property' => 'option_1',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 20,
'objectid' => 'field_test_integer_selectlist',
'type' => 'field',
'property' => 'option_1234',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 21,
'objectid' => 'field_test_integer_selectlist',
'type' => 'field',
'property' => 'option_4123',
'objectindex' => 0,
'format' => 0,
],
];
$test[0]['source_data']['locales_target'] = [
[
'lid' => 10,
'translation' => "fr - Hello",
'language' => 'fr',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 11,
'translation' => 'fr - Goodbye',
'language' => 'fr',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 20,
'translation' => "fr - 4444",
'language' => 'fr',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 21,
'translation' => 'fr - 5555',
'language' => 'fr',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
];
$test[0]['expected_results'] = [
[
'field_name' => 'field_test_text_single_checkbox',
'type' => 'text',
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => 'Off\nHello',
'allowed_values_php' => '',
'max_length' => '',
'text_processing' => '0',
],
'db_columns' => '',
'property' => 'option_0',
'objectid' => 'field_test_text_single_checkbox',
'language' => 'fr',
'translation' => 'fr - Hello',
'objectindex' => 0,
'format' => 0,
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'field_name' => 'field_test_text_single_checkbox',
'type' => 'text',
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => 'Off\nHello',
'allowed_values_php' => '',
'max_length' => '',
'text_processing' => '0',
],
'db_columns' => '',
'property' => 'option_1',
'objectid' => 'field_test_text_single_checkbox',
'language' => 'fr',
'translation' => 'fr - Goodbye',
'objectindex' => 0,
'format' => 0,
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'field_name' => 'field_test_integer_selectlist',
'type' => 'number_integer',
'widget_type' => 'optionwidgets_select',
'global_settings' => [
'allowed_values' => '1234\n2341\n3412\n4123',
'max' => '',
'min' => '',
'prefix' => '',
'suffix' => '',
'allowed_values_php' => '',
],
'db_columns' => '',
'property' => 'option_1234',
'objectid' => 'field_test_integer_selectlist',
'language' => 'fr',
'translation' => 'fr - 4444',
'objectindex' => 0,
'format' => 0,
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'field_name' => 'field_test_integer_selectlist',
'type' => 'number_integer',
'widget_type' => 'optionwidgets_select',
'global_settings' => [
'allowed_values' => '1234\n2341\n3412\n4123',
'max' => '',
'min' => '',
'prefix' => '',
'suffix' => '',
'allowed_values_php' => '',
],
'db_columns' => '',
'property' => 'option_4123',
'objectid' => 'field_test_integer_selectlist',
'language' => 'fr',
'translation' => 'fr - 5555',
'objectindex' => 0,
'format' => 0,
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
];
return $test;
}
}
@@ -0,0 +1,64 @@
<?php
namespace Drupal\Tests\field\Traits;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Provides common functionality for the EntityReference test classes.
*/
trait EntityReferenceTestTrait {
/**
* Creates a field of an entity reference field storage on the specified bundle.
*
* @param string $entity_type
* The type of entity the field will be attached to.
* @param string $bundle
* The bundle name of the entity the field will be attached to.
* @param string $field_name
* The name of the field; if it already exists, a new instance of the existing
* field will be created.
* @param string $field_label
* The label of the field.
* @param string $target_entity_type
* The type of the referenced entity.
* @param string $selection_handler
* The selection handler used by this field.
* @param array $selection_handler_settings
* An array of settings supported by the selection handler specified above.
* (e.g. 'target_bundles', 'sort', 'auto_create', etc).
* @param int $cardinality
* The cardinality of the field.
*
* @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()
*/
protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) {
// Look for or add the specified field to the requested entity bundle.
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
FieldStorageConfig::create([
'field_name' => $field_name,
'type' => 'entity_reference',
'entity_type' => $entity_type,
'cardinality' => $cardinality,
'settings' => [
'target_type' => $target_entity_type,
],
])->save();
}
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'label' => $field_label,
'settings' => [
'handler' => $selection_handler,
'handler_settings' => $selection_handler_settings,
],
])->save();
}
}
}