core/modules/taxonomy/src/Entity/Term.php | 15 ++++++++++++++- .../modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 06af409..f686eb0 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -255,7 +255,20 @@ public function getParents() { } $ids[] = $item->target_id; } - return $parents + static::loadMultiple($ids); + + // @todo Better way to do this? AND handle the NULL/0 parent? + // Querying the terms again so that the same access checks are run when + // getParents() is called as in Drupal version prior to 8.3. + $loaded_parents = []; + + if ($ids) { + $query = \Drupal::entityQuery('taxonomy_term') + ->condition('tid', $ids, 'IN'); + + $loaded_parents = static::loadMultiple($query->execute()); + } + + return $parents + $loaded_parents; } /** diff --git a/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php b/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php index 543910b..0788bef 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php @@ -32,7 +32,7 @@ public function testTaxonomyQueryAlter() { } // Set up hierarchy. Term 2 is a child of 1. - $terms[2]->parent = $terms[1]->id(); + $terms[2]->parent->setValue($terms[1]->id()); $terms[2]->save(); $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); @@ -50,12 +50,12 @@ public function testTaxonomyQueryAlter() { $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadParents($terms[2]->id()); $this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded'); - $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadParents()'); + $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadParents()'); $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadChildren($terms[1]->id()); $this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded'); - $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadChildren()'); + $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadChildren()'); $this->setupQueryTagTestHooks(); $query = db_select('taxonomy_term_data', 't');