diff --git a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml index 99004dfed6b7c3d8a7ef679e02735221f3602f4e..46f9f20427f799116d9c91f43e8970696b267b15 100644 --- a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml +++ b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml @@ -30,6 +30,7 @@ process: plugin: default_value default_value: 0 source: '@parent_id' + forum_container: is_container changed: timestamp destination: plugin: entity:taxonomy_term diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php index a9711a1b66a05101af556683823712e1afeb93f4..93b0fc4aaa45b4d98a8629197de52b0d8f2d9063 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php @@ -70,6 +70,11 @@ public function prepareRow(Row $row) { ->fetchCol(); $row->setSourceProperty('parent', $parents); + // Determine if this is a forum container. + $forum_container_tids = $this->variableGet('forum_containers', []); + $current_tid = $row->getSourceProperty('tid'); + $row->setSourceProperty('is_container', in_array($current_tid, $forum_container_tids)); + return parent::prepareRow($row); } diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index 207b52858994b51529e6ba2c51ab729203ce5e37..474969dde1f38e6b05069aab7344e502b4ca4ea8 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -16,6 +16,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { public static $modules = [ 'comment', 'datetime', + 'forum', 'image', 'link', 'menu_ui', @@ -71,17 +72,19 @@ protected function setUp() { * The value the migrated entity field should have. * @param int $expected_term_reference_tid * The term reference id the migrated entity field should have. + * @param bool $expected_container_flag + * The term should be a container entity. */ - protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) { + protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = 0) { /** @var \Drupal\taxonomy\TermInterface $entity */ $entity = Term::load($id); - $this->assertTrue($entity instanceof TermInterface); - $this->assertIdentical($expected_label, $entity->label()); - $this->assertIdentical($expected_vid, $entity->bundle()); - $this->assertEqual($expected_description, $entity->getDescription()); + $this->assertInstanceOf(TermInterface::class, $entity); + $this->assertEquals($expected_label, $entity->label()); + $this->assertEquals($expected_vid, $entity->bundle()); + $this->assertEquals($expected_description, $entity->getDescription()); $this->assertEquals($expected_format, $entity->getFormat()); - $this->assertEqual($expected_weight, $entity->getWeight()); - $this->assertIdentical($expected_parents, $this->getParentIDs($id)); + $this->assertEquals($expected_weight, $entity->getWeight()); + $this->assertEquals($expected_parents, $this->getParentIDs($id)); $this->assertHierarchy($expected_vid, $id, $expected_parents); if (!is_null($expected_field_integer_value)) { $this->assertTrue($entity->hasField('field_integer')); @@ -91,6 +94,9 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d $this->assertTrue($entity->hasField('field_integer')); $this->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id); } + if ($entity->hasField('forum_container')) { + $this->assertEquals($expected_container_flag, $entity->forum_container->value); + } } /** @@ -102,9 +108,17 @@ public function testTaxonomyTerms() { $this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html'); $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6); $this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3); - $this->assertEntity(6, 'Games', 'forums', '', NULL, 4); + $this->assertEntity(6, 'Games', 'forums', '', NULL, 4, [], NULL, NULL, 1); $this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]); $this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]); + + // Verify that we still can create forum containers after the migration. + $term = Term::create(['vid' => 'forums', 'name' => 'Forum Container', 'forum_container' => 1]); + $term->save(); + + // Reset the forums tree data so this new term is included in the tree. + unset($this->treeData['forums']); + $this->assertEntity(19, 'Forum Container', 'forums', '', NULL, 0, [], NULL, NULL, 1); } /** diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php index be905d9dc736ccbfe3141005ed2154d94d188a9c..dd22672a0a496e3532bf2219627cd638d782d58a 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php @@ -31,6 +31,7 @@ public function providerSource() { 'name' => 'name value 1', 'description' => 'description value 1', 'weight' => 0, + 'is_container' => FALSE, ], [ 'tid' => 2, @@ -38,6 +39,7 @@ public function providerSource() { 'name' => 'name value 2', 'description' => 'description value 2', 'weight' => 0, + 'is_container' => TRUE, ], [ 'tid' => 3, @@ -45,6 +47,7 @@ public function providerSource() { 'name' => 'name value 3', 'description' => 'description value 3', 'weight' => 0, + 'is_container' => FALSE, ], [ 'tid' => 4, @@ -52,6 +55,7 @@ public function providerSource() { 'name' => 'name value 4', 'description' => 'description value 4', 'weight' => 1, + 'is_container' => FALSE, ], [ 'tid' => 5, @@ -59,6 +63,7 @@ public function providerSource() { 'name' => 'name value 5', 'description' => 'description value 5', 'weight' => 1, + 'is_container' => FALSE, ], [ 'tid' => 6, @@ -66,6 +71,7 @@ public function providerSource() { 'name' => 'name value 6', 'description' => 'description value 6', 'weight' => 0, + 'is_container' => TRUE, ], [ 'tid' => 7, @@ -73,6 +79,7 @@ public function providerSource() { 'name' => 'name value 7', 'description' => 'description value 7', 'weight' => 0, + 'is_container' => TRUE, ], ]; $tests[0]['source_data']['taxonomy_term_hierarchy'] = [ @@ -149,6 +156,12 @@ public function providerSource() { 'delta' => 0, ], ]; + $tests[0]['source_data']['variable'] = [ + [ + 'name' => 'forum_containers', + 'value' => 'a:3:{i:0;s:1:"5";i:1;s:1:"6";i:2;s:1:"7";}', + ], + ]; // The expected results. $tests[0]['expected_data'] = [