diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index 1a517c0..3f7b8e9 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -129,14 +129,8 @@ protected function actions(array $form, FormStateInterface $form_state) { */ protected function forumParentSelect($tid, $title) { $taxonomy_storage = $this->entityManager->getStorage('taxonomy_term'); - $parents = $taxonomy_storage->loadParents($tid); - if ($parents) { - $parent = array_shift($parents); - $parent = $parent->id(); - } - else { - $parent = 0; - } + $parents = array_keys($taxonomy_storage->loadParents($tid)); + $parent = reset($parents); $vid = $this->config('forum.settings')->get('vocabulary'); $children = $taxonomy_storage->loadTree($vid, $tid, NULL, TRUE); diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index 38ca761..b844a32 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -126,23 +126,26 @@ public function updateTermHierarchy(EntityInterface $term) { public function loadParents($tid) { if (!isset($this->parents[$tid])) { $parents = array(); - $query = $this->database->select('taxonomy_term_field_data', 't'); - $query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid'); - $query->addField('t', 'tid'); + $query = $this->database->select('taxonomy_term_hierarchy', 'h'); + $query->leftJoin('taxonomy_term_field_data', 't', 'h.parent = t.tid'); + $query->addField('h', 'parent'); $query->condition('h.tid', $tid); - $query->condition('t.default_langcode', 1); + $query->condition($query->orConditionGroup() + ->condition('h.parent', 0) + ->condition('t.default_langcode', 1) + ); $query->addTag('term_access'); $query->orderBy('t.weight'); $query->orderBy('t.name'); $ids = $query->execute()->fetchCol(); if ($ids) { - // If there is a parent in the list, it will be filtered out in - // loadMultiple() because there's no entity associated with the . - // In this case, the parent is added with key 0 and NULL. - if (in_array(0, $ids)) { - $parents[0] = NULL; + $terms = $this->loadMultiple($ids); + foreach ($ids as $id) { + // The parent was filtered out in loadMultiple() because + // there's no entity associated with . In this case, the parent + // is re-added with key 0 and NULL. + $parents[$id] = $id != 0 ? $terms[$id] : NULL; } - $parents += $this->loadMultiple($ids); } $this->parents[$tid] = $parents; } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/src/Tests/Migrate/d7/MigrateTaxonomyTermTest.php index 6c01697..8937141 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d7/MigrateTaxonomyTermTest.php @@ -61,12 +61,12 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d * Tests the Drupal 7 taxonomy term to Drupal 8 migration. */ public function testTaxonomyTerms() { - $this->assertEntity(1, 'General discussion', 'forums', '', 2); - $this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.'); - $this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.'); + $this->assertEntity(1, 'General discussion', 'forums', '', 2, [0]); + $this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 0, [0]); + $this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 0, [0]); $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 0, [3]); - $this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3); - $this->assertEntity(6, 'Games', 'forums', '', 4); + $this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3, [0]); + $this->assertEntity(6, 'Games', 'forums', '', 4, [0]); $this->assertEntity(7, 'Minecraft', 'forums', '', 1, [6]); $this->assertEntity(8, 'Half Life 3', 'forums', '', 0, [6]); } diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php b/core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php index 322c92b..d3f7355 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php @@ -74,10 +74,10 @@ function testTermIndentation() { // All terms back at the root level, no indentation should be present. $this->assertNoPattern('|
 
|'); - // Check explicitly that term 2 has no parents. + // Check explicitly that term 2 has no other parents than the parent. \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache(); $parents = $taxonomy_storage->loadParents($term2->id()); - $this->assertTrue(empty($parents), 'Term 2 has no parents now'); + $this->assertIdentical($parents, array(0 => NULL)); } } diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 9d06719..f9d4daf 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -458,7 +458,9 @@ function testTermMultipleParentsInterface() { // Check that the parent tid is still there. The other parent () is // not added by \Drupal\taxonomy\TermStorageInterface::loadParents(). $parents = $this->container->get('entity.manager')->getStorage('taxonomy_term')->loadParents($term->id()); - $parent = reset($parents); + $parent = key($parents); + $this->assertEqual($edit['parent[]'][0], $parent); + $parent = $parents[1]; $this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.'); }