diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 5b0072b87d8..0c3a0ebbf23 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -229,7 +229,8 @@ class Term extends ContentEntityBase implements TermInterface { * {@inheritdoc} */ public function getVocabularyId() { - return $this->get('vid')->target_id; + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.4.0 and will be removed before 9.0.0. Use ' . __CLASS__ . '::bundle() instead to get the vocabulary ID.', E_USER_DEPRECATED); + return $this->bundle(); } } diff --git a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php index 513ed7e78d9..33517b15aa1 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php @@ -194,7 +194,7 @@ class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterf $taxonomy_terms = $node->{$field->getName()}->referencedEntities(); /** @var \Drupal\taxonomy\TermInterface $taxonomy_term */ foreach ($taxonomy_terms as $taxonomy_term) { - $taxonomy[$taxonomy_term->id()] = $taxonomy_term->getVocabularyId(); + $taxonomy[$taxonomy_term->id()] = $taxonomy_term->bundle(); } } } diff --git a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php index 86a4fce2191..f33421a9f2f 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php @@ -145,8 +145,8 @@ class TaxonomyIndexTid extends PrerenderList { foreach ($data as $tid => $term) { $this->items[$node_nid][$tid]['name'] = \Drupal::entityManager()->getTranslationFromContext($term)->label(); $this->items[$node_nid][$tid]['tid'] = $tid; - $this->items[$node_nid][$tid]['vocabulary_vid'] = $term->getVocabularyId(); - $this->items[$node_nid][$tid]['vocabulary'] = $vocabularies[$term->getVocabularyId()]->label(); + $this->items[$node_nid][$tid]['vocabulary_vid'] = $term->bundle(); + $this->items[$node_nid][$tid]['vocabulary'] = $vocabularies[$term->bundle()]->label(); if (!empty($this->options['link_to_taxonomy'])) { $this->items[$node_nid][$tid]['make_link'] = TRUE; diff --git a/core/modules/taxonomy/src/TermInterface.php b/core/modules/taxonomy/src/TermInterface.php index f832620ee77..9c0c47efb97 100644 --- a/core/modules/taxonomy/src/TermInterface.php +++ b/core/modules/taxonomy/src/TermInterface.php @@ -87,6 +87,9 @@ interface TermInterface extends ContentEntityInterface, EntityChangedInterface { * * @return int * The id of the vocabulary. + * + * @deprecated Scheduled for removal before Drupal 9.0.0. Use + * TermInterface::bundle() instead. */ public function getVocabularyId(); diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldAllTermsTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldAllTermsTest.php index 4737b989dc8..75894ce4332 100644 --- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldAllTermsTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldAllTermsTest.php @@ -57,7 +57,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase { $this->assertText('The taxonomy term name for the term: ' . $this->term1->getName()); // The machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }} - $this->assertText('The machine name for the vocabulary the term belongs to: ' . $this->term1->getVocabularyId()); + $this->assertText('The machine name for the vocabulary the term belongs to: ' . $this->term1->bundle()); // The name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }} $vocabulary = Vocabulary::load($this->term1->bundle()); 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 fbcc1297953..214e7841308 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -76,7 +76,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { $entity = Term::load($id); $this->assertTrue($entity instanceof TermInterface); $this->assertIdentical($expected_label, $entity->label()); - $this->assertIdentical($expected_vid, $entity->getVocabularyId()); + $this->assertIdentical($expected_vid, $entity->bundle()); $this->assertEqual($expected_description, $entity->getDescription()); $this->assertEquals($expected_format, $entity->getFormat()); $this->assertEqual($expected_weight, $entity->getWeight());