diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index f034397..1a517c0 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -128,7 +128,8 @@ protected function actions(array $form, FormStateInterface $form_state) { * A select form element. */ protected function forumParentSelect($tid, $title) { - $parents = $this->entityManager->getStorage('taxonomy_term')->loadParents($tid); + $taxonomy_storage = $this->entityManager->getStorage('taxonomy_term'); + $parents = $taxonomy_storage->loadParents($tid); if ($parents) { $parent = array_shift($parents); $parent = $parent->id(); @@ -138,7 +139,7 @@ protected function forumParentSelect($tid, $title) { } $vid = $this->config('forum.settings')->get('vocabulary'); - $children = $this->entityManager->getStorage('taxonomy_term')->loadTree($vid, $tid, NULL, TRUE); + $children = $taxonomy_storage->loadTree($vid, $tid, NULL, TRUE); // A term can't be the child of itself, nor of its children. foreach ($children as $child) { @@ -146,7 +147,7 @@ protected function forumParentSelect($tid, $title) { } $exclude[] = $tid; - $tree = $this->entityManager->getStorage('taxonomy_term')->loadTree($vid, 0, NULL, TRUE); + $tree = $taxonomy_storage->loadTree($vid, 0, NULL, TRUE); $options[0] = '<' . $this->t('root') . '>'; if ($tree) { foreach ($tree as $term) { diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index c2c7154..cc0cbf3 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -21,9 +21,10 @@ class TermForm extends ContentEntityForm { public function form(array $form, FormStateInterface $form_state) { $term = $this->entity; $vocab_storage = $this->entityManager->getStorage('taxonomy_vocabulary'); + $taxonomy_storage = $this->entityManager->getStorage('taxonomy_term'); $vocabulary = $vocab_storage->load($term->bundle()); - $parent = array_keys($this->entityManager->getStorage('taxonomy_term')->loadParents($term->id())); + $parent = array_keys($taxonomy_storage->loadParents($term->id())); $form_state->set(['taxonomy', 'parent'], $parent); $form_state->set(['taxonomy', 'vocabulary'], $vocabulary); @@ -35,13 +36,13 @@ public function form(array $form, FormStateInterface $form_state) { ); // \Drupal\taxonomy\TermStorage::loadTree() and - // Drupal\taxonomy\TermStorageController::loadParents() may contain large + // \Drupal\taxonomy\TermStorageController::loadParents() may contain large // numbers of items so we check for taxonomy.settings:override_selector // before loading the full vocabulary. Contrib modules can then intercept // before hook_form_alter to provide scalable alternatives. if (!$this->config('taxonomy.settings')->get('override_selector')) { - $parent = array_keys($this->entityManager->getStorage('taxonomy_term')->loadParents($term->id())); - $children = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), $term->id()); + $parent = array_keys($taxonomy_storage->loadParents($term->id())); + $children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id()); // A term can't be the child of itself, nor of its children. foreach ($children as $child) { @@ -49,7 +50,7 @@ public function form(array $form, FormStateInterface $form_state) { } $exclude[] = $term->id(); - $tree = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id()); + $tree = $taxonomy_storage->loadTree($vocabulary->id()); $options = array('<' . $this->t('root') . '>'); if (empty($parent)) { $parent = array(0); diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 781a501..45e32da 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -81,22 +81,22 @@ function testTaxonomyTermHierarchy() { $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save')); // Check the hierarchy. - $children = \Drupal::entityManager()->getStorage('taxonomy_term')->loadChildren($term1->id()); - $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term2->id()); + $children = $this->container->get('entity.manager')->loadChildren($term1->id()); + $parents = $this->container->get('entity.manager')->loadParents($term2->id()); $this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.'); $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.'); // Load and save a term, confirming that parents are still set. $term = Term::load($term2->id()); $term->save(); - $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term2->id()); + $parents = $this->container->get('entity.manager')->loadParents($term2->id()); $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.'); // Create a third term and save this as a parent of term2. $term3 = $this->createTerm($this->vocabulary); $term2->parent = array($term1->id(), $term3->id()); $term2->save(); - $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term2->id()); + $parents = $this->container->get('entity.manager')->loadParents($term2->id()); $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.'); } @@ -121,8 +121,8 @@ function testTaxonomyTermChildTerms() { $edit['parent'] = $term1->id(); } $term = $this->createTerm($this->vocabulary, $edit); - $children = \Drupal::entityManager()->getStorage('taxonomy_term')->loadChildren($term1->id()); - $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term->id()); + $children = $this->container->get('entity.manager')->loadChildren($term1->id()); + $parents = $this->container->get('entity.manager')->loadParents($term->id()); $terms_array[$x] = Term::load($term->id()); } @@ -232,7 +232,7 @@ function testNodeTermCreationAndDeletion() { foreach ($terms as $term) { $this->assertText($term, 'The term appears on the node preview.'); } - $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($this->vocabulary->id()); + $tree = $this->container->get('entity.manager')->loadTree($this->vocabulary->id()); $this->assertTrue(empty($tree), 'The terms are not created on preview.'); // taxonomy.module does not maintain its static caches. @@ -370,8 +370,8 @@ function testTermReorder() { // Fetch the created terms in the default alphabetical order, i.e. term1 // precedes term2 alphabetically, and term2 precedes term3. - \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache(); - list($term1, $term2, $term3) = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($this->vocabulary->id(), 0, NULL, TRUE); + $this->container->get('entity.manager')->resetCache(); + list($term1, $term2, $term3) = $this->container->get('entity.manager')->loadTree($this->vocabulary->id(), 0, NULL, TRUE); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); @@ -395,8 +395,8 @@ function testTermReorder() { ); $this->drupalPostForm(NULL, $edit, t('Save')); - \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache(); - $terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($this->vocabulary->id()); + $this->container->get('entity.manager')->resetCache(); + $terms = $this->container->get('entity.manager')->loadTree($this->vocabulary->id()); $this->assertEqual($terms[0]->tid, $term2->id(), 'Term 2 was moved above term 1.'); $this->assertEqual($terms[1]->parents, array($term2->id()), 'Term 3 was made a child of term 2.'); $this->assertEqual($terms[2]->tid, $term1->id(), 'Term 1 was moved below term 2.'); @@ -407,8 +407,8 @@ function testTermReorder() { // Ensure form redirected back to overview. $this->assertUrl('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); - \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache(); - $terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($this->vocabulary->id(), 0, NULL, TRUE); + $this->container->get('entity.manager')->resetCache(); + $terms = $this->container->get('entity.manager')->loadTree($this->vocabulary->id(), 0, NULL, TRUE); $this->assertEqual($terms[0]->id(), $term1->id(), 'Term 1 was moved to back above term 2.'); $this->assertEqual($terms[1]->id(), $term2->id(), 'Term 2 was moved to back below term 1.'); $this->assertEqual($terms[2]->id(), $term3->id(), 'Term 3 is still below term 2.'); @@ -439,8 +439,8 @@ function testTermMultipleParentsInterface() { $this->assertEqual($edit['description[0][value]'], $term->getDescription(), 'Term description was successfully saved.'); // Check that the parent tid is still there. The other parent () is // not added by - // \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents(). - $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term->id()); + // $this->container->get('entity.manager')->loadParents(). + $parents = $this->container->get('entity.manager')->loadParents($term->id()); $parent = reset($parents); $this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.'); } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index 3a96625..f5ba24e 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -97,7 +97,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $replacements = array(); $sanitize = !empty($options['sanitize']); - + $taxonomy_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); if ($type == 'term' && !empty($data['term'])) { $term = $data['term']; @@ -133,7 +133,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'parent': - if ($parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term->id())) { + if ($parents = $taxonomy_storage->loadParents($term->id())) { $parent = array_pop($parents); $replacements[$original] = SafeMarkup::checkPlain($parent->getName()); } @@ -146,7 +146,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); } - if (($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'parent')) && $parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($term->id())) { + if (($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'parent')) && $parents = $taxonomy_storage->loadParents($term->id())) { $parent = array_pop($parents); $replacements += $token_service->generate('term', $vocabulary_tokens, array('term' => $parent), $options); } @@ -178,7 +178,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'node-count': - $replacements[$original] = \Drupal::entityManager()->getStorage('taxonomy_term')->nodeCount($vocabulary->id()); + $replacements[$original] = $taxonomy_storage->nodeCount($vocabulary->id()); break; } }