diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 2ee839c..1559acf 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -667,7 +667,8 @@ private function verifyForumView($forum, $parent = NULL) { '#theme' => 'breadcrumb', '#links' => $breadcrumb_build, ); - $this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed'); + $rendered_breadcrumb = \Drupal::service('renderer')->renderRoot($breadcrumb); + $this->assertRaw($rendered_breadcrumb, 'Breadcrumbs were displayed'); } /** diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 16d31c1..0850780 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -90,10 +90,10 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti } } } + } - if (!empty($orphans)) { - entity_delete_multiple('taxonomy_term', $orphans); - } + if (!empty($orphans)) { + entity_delete_multiple('taxonomy_term', $orphans); } } @@ -103,15 +103,8 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); - $parents = $this->getParents(); - foreach ($parents as $delta => $item) { - // Assure that parent is strict 0. - if (empty($item->target_id) && $item->target_id !== 0) { - } - } - // Terms with no parents are mandatory children of . - if (!$parents->count()) { + if (!$this->getParents()->count()) { $this->parent->target_id = 0; } } @@ -312,7 +305,7 @@ public function getChildren($vid = NULL) { if ($vid) { $query->condition('vid', $vid); } - return $this->loadMultiple($query->execute()); + return static::loadMultiple($query->execute()); } } diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index 3d5e186..c349ead 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -132,17 +132,14 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Reflect machine name changes in the definitions of existing 'taxonomy' // fields. $field_ids = array(); - $field_map = \Drupal::entityManager() - ->getFieldMapByFieldType('entity_reference'); + $field_map = \Drupal::entityManager()->getFieldMapByFieldType('entity_reference'); foreach ($field_map as $entity_type => $field_storages) { foreach ($field_storages as $field_storage => $info) { $field_ids[] = $entity_type . '.' . $field_storage; } } - $field_storages = \Drupal::entityManager() - ->getStorage('field_storage_config') - ->loadMultiple($field_ids); + $field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple($field_ids); $taxonomy_fields = array_filter($field_storages, function ($field_storage) { return $field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term'; }); diff --git a/core/modules/taxonomy/src/TermInterface.php b/core/modules/taxonomy/src/TermInterface.php index 7e892c7..e4b8435 100644 --- a/core/modules/taxonomy/src/TermInterface.php +++ b/core/modules/taxonomy/src/TermInterface.php @@ -108,7 +108,7 @@ public function getParents(); * Returns all ancestors of this term. * * @return \Drupal\taxonomy\TermInterface[] - * A list of references to all ancestor taxonomy terms. + * A list of ancestor taxonomy term entities keyed by term id. */ public function getAncestors(); @@ -119,7 +119,7 @@ public function getAncestors(); * An optional vocabulary ID to restrict the child search. * * @return \Drupal\taxonomy\TermInterface[] - * A list of references to children taxonomy terms. + * A list of children taxonomy term entities keyed by term id. */ public function getChildren($vid = NULL); diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index 19cf451..b147501 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -129,7 +129,7 @@ public function loadTree($vid, $parent = 0, $max_depth = NULL, $load_entities = $this->treeParents[$vid] = array(); $this->treeTerms[$vid] = array(); $query = $this->database->select('taxonomy_term_field_data', 't'); - $query->leftJoin('taxonomy_term__parent', 'p', 't.tid = p.entity_id'); + $query->join('taxonomy_term__parent', 'p', 't.tid = p.entity_id'); $query->addExpression('parent_target_id', 'parent'); $result = $query ->addTag('term_access') diff --git a/core/modules/taxonomy/src/Tests/TermKernelTest.php b/core/modules/taxonomy/src/Tests/TermKernelTest.php index 4d0c17b..cc44bfc 100644 --- a/core/modules/taxonomy/src/Tests/TermKernelTest.php +++ b/core/modules/taxonomy/src/Tests/TermKernelTest.php @@ -148,6 +148,6 @@ public function testTaxonomyVocabularyTree() { // Identify all ancestors of $term[3]. $ancestors = $storage->loadAllParents($term[3]->id()); - $this->assertEqual(5, count($ancestors)/*, 'The term has five ancestors including the term itself.'*/); + $this->assertEqual(5, count($ancestors), 'The term has five ancestors including the term itself.'); } } diff --git a/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php index e14b516..a5ba473 100644 --- a/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests\Update; +use Drupal\Component\Serialization\Yaml; +use Drupal\Component\Utility\Unicode; use Drupal\system\Tests\Update\UpdatePathTestBase; use Drupal\taxonomy\Entity\Term; @@ -30,6 +32,13 @@ class TaxonomyUpdateTest extends UpdatePathTestBase { protected $db; /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** * {@inheritdoc} */ public function setDatabaseDumpFiles() { @@ -44,6 +53,7 @@ public function setDatabaseDumpFiles() { protected function setUp() { parent::setUp(); $this->db = $this->container->get('database'); + $this->configFactory = $this->container->get('config.factory'); } /** @@ -53,6 +63,7 @@ protected function setUp() { */ public function testTaxonomyUpdate8001() { $tids = $this->createTerms(); + $vid = $this->createView(); // Run updates. $this->runUpdates(); @@ -75,6 +86,12 @@ public function testTaxonomyUpdate8001() { // Target ID is returned as string. $this->assertIdentical((int) $term->get('parent')[0]->target_id, 0); + // Test if the view has been converted to use {taxonomy_term__parent} table + // instead of {taxonomy_term_hierarchy}. + $view = $this->configFactory->get("views.view.$vid"); + $path = 'display.default.display_options.relationships.parent.table'; + $this->assertIdentical($view->get($path), 'taxonomy_term__parent'); + // The {taxonomy_term_hierarchy} table has been removed. $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy')); } @@ -121,4 +138,23 @@ protected function createTerms() { return $tids; } + /** + * Creates a test view using a low level API. + * + * @return string + * The view id. + */ + protected function createView() { + $vid = Unicode::strtolower($this->randomMachineName()); + $file = __DIR__ . '/../../../tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; + + $this->configFactory->getEditable("views.view.$vid") + ->setData(Yaml::decode(file_get_contents($file))) + // Revert the change done in taxonomy_update_8001(). + ->set('display.default.display_options.relationships.parent.table', 'taxonomy_term_hierarchy') + ->save(); + + return $vid; + } + } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 82b6778..2369dad 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the taxonomy module. */ -use Drupal\Core\Field\BaseFieldDefinition; - /** * Convert the custom taxonomy term hierarchy storage to a default storage. */ @@ -64,6 +62,23 @@ function taxonomy_update_8001(&$sandbox = NULL) { $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']); if ($sandbox['#finished'] >= 1) { + $factory = \Drupal::configFactory(); + // Update views with a low level API. + foreach ($factory->listAll('views.view.') as $id) { + $view = $factory->getEditable($id); + $changed = FALSE; + foreach ($view->get('display') as $display_id => &$display) { + $path = "display.$display_id.display_options.relationships.parent.table"; + if (!empty($table = $view->get($path)) && $table == 'taxonomy_term_hierarchy') { + $view->set($path, 'taxonomy_term__parent'); + $changed = TRUE; + } + } + if ($changed) { + $view->save(TRUE); + } + } + // Drop the legacy table. $database->schema()->dropTable('taxonomy_term_hierarchy'); return t('Taxonomy term hierarchy converted.');