Commit 88868d81 authored by catch's avatar catch
Browse files

Issue #3042533 by quietone, danflanagan8: D6 taxonomy term fields are not...

Issue #3042533 by quietone, danflanagan8: D6 taxonomy term fields are not migrated with allowed vocabularies

(cherry picked from commit 66449600)
parent 9caf7d9a
......@@ -47,8 +47,17 @@ process:
plugin: forum_vocabulary
machine_name: taxonomy_forums
label: name
_vid:
-
plugin: migration_lookup
migration: d6_taxonomy_vocabulary
source: vid
-
plugin: skip_on_empty
method: row
'settings/handler': 'constants/selection_handler'
'settings/handler_settings/target_bundles/0': '@field_name'
'settings/handler_settings/target_bundles':
plugin: target_bundle
'settings/handler_settings/auto_create': 'constants/auto_create'
required: required
# Get the i18n taxonomy translation setting for this vocabulary.
......
<?php
namespace Drupal\taxonomy\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Converts a Drupal 6 vocabulary ID to a target bundle array.
*
* @MigrateProcessPlugin(
* id = "target_bundle"
* )
*/
class TargetBundle extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$target_bundle = [];
$vid = $row->get('@_vid');
$target_bundle[$vid] = $vid;
return $target_bundle;
}
}
......@@ -46,6 +46,7 @@ public function testVocabularyFieldInstance() {
$this->assertSame('Tags', $field->label());
$this->assertTrue($field->isRequired(), 'Field is required');
$this->assertFalse($field->isTranslatable());
$this->assertTargetBundles($field_id, ['tags' => 'tags']);
// Test the page bundle as well. Tags has a multilingual option of 'None'.
$field_id = 'node.page.field_tags';
......@@ -57,7 +58,7 @@ public function testVocabularyFieldInstance() {
$settings = $field->getSettings();
$this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
$this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
$this->assertTargetBundles($field_id, ['tags' => 'tags']);
$this->assertTrue($settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
$this->assertSame([['node', 'article', 'field_tags']], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationIds([4, 'article']));
......@@ -68,6 +69,7 @@ public function testVocabularyFieldInstance() {
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertTrue($field->isTranslatable());
$this->assertTargetBundles($field_id, ['vocabulary_1_i_0_' => 'vocabulary_1_i_0_']);
// Test the field vocabulary_2_i_0_ with multilingual option,
// 'Set language to vocabulary'.
......@@ -75,6 +77,7 @@ public function testVocabularyFieldInstance() {
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertFalse($field->isTranslatable());
$this->assertTargetBundles($field_id, ['vocabulary_2_i_1_' => 'vocabulary_2_i_1_']);
// Test the field vocabulary_3_i_0_ with multilingual option,
// 'Localize terms'.
......@@ -82,12 +85,32 @@ public function testVocabularyFieldInstance() {
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertTrue($field->isTranslatable());
$this->assertTargetBundles($field_id, ['vocabulary_3_i_2_' => 'vocabulary_3_i_2_']);
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = FieldConfig::load('node.sponsor.field_type');
$this->assertInstanceOf(FieldConfig::class, $field_type);
$this->assertTrue($field->isTranslatable());
$this->assertTargetBundles($field_id, ['vocabulary_3_i_2_' => 'vocabulary_3_i_2_']);
$this->assertTargetBundles('node.employee.field_vocabulary_3_i_2_', ['vocabulary_3_i_2_' => 'vocabulary_3_i_2_']);
}
/**
* Asserts the settings of an entity reference field config entity.
*
* @param string $id
* The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
* @param string[] $target_bundles
* An array of expected target bundles.
*/
protected function assertTargetBundles($id, array $target_bundles) {
$field = FieldConfig::load($id);
$handler_settings = $field->getSetting('handler_settings');
$this->assertArrayHasKey('target_bundles', $handler_settings);
$this->assertSame($handler_settings['target_bundles'], $target_bundles);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment