Problem/Motivation

When I tried to get vocabulary id of some taxonome term using Drupal\taxonomy\TermInterface::getVocabularyId() method I received strange result. TermInterface said, that getVocabularyId() should return "The id of the vocabulary." and it should be integer. But I received string with vocabulary machine name. In my code I need exectly vocabulary machine name, so the problem is in the method name.
Here is code I've used:

$term = $route_match->getParameter('taxonomy_term');
if ($term instanceof taxonomy\TermInterface) {
  $vocabulary = $term->getVocabularyId(); // return "blog_categories"
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Goodmood created an issue. See original summary.

Michelle’s picture

Looks like this was caught in the spam trap. Publishing.

swentel’s picture

Vocabularies don't have an int, so the docs are wrong, it should say that it returns a string instead of an integer.
So the method returns the right thing, it's just that the docs are wrong.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Status: Active » Closed (works as designed)

Yes, it should return the ID which is a "machine name". Vocabularies are config entities with the ID as string.

iMiksu’s picture

Status: Closed (works as designed) » Active
Issue tags: +Novice, +Needs documentation updates

The point is not "ID", the point is "integer", see the current code from 8.3.x head:

  /**
   * Get the taxonomy vocabulary id this term belongs to.
   *
   * @return int
   *   The id of the vocabulary.
   */
  public function getVocabularyId();

This was confusing to me also. The docs are misleading and needs to be fixed.

shashikant_chauhan’s picture

Status: Active » Needs review
FileSize
477 bytes

Adding patch.

claudiu.cristea’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Needs review » Reviewed & tested by the community

This is already deprecated in 8.4.x (see http://cgit.drupalcode.org/drupal/tree/core/modules/taxonomy/src/TermInt...). Probably will need a port?

claudiu.cristea’s picture

Title: TermInterface::getVocabularyId() method return vocabulary machine name (string) instead of vocabulary id (int) » Fix TermInterface::getVocabularyId() method return type in documentation
Version: 8.4.x-dev » 8.3.x-dev

Fixing title as per #8 and reverted to 8.3.x

catch’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Baltimore2017, +Needs re-roll

Even though it's deprecated in 8.4.x, the docs are still incorrect, so I think it's more important to fix in 8.4.x since we can't actually remove the method until 9.0.0. However it needs a re-roll for 8.4.x

sathish.redcrackle’s picture

re-roll for 8.4.x

sathish.redcrackle’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC.

@catch, I was thinking that it would had been better if this is committed also on 8.3.x because this, being documentation, will be also persistent on http://api.drupal.org many years after 8.3.x will be no more supported.

chiranjeeb2410’s picture

Assigned: Unassigned » chiranjeeb2410
Status: Reviewed & tested by the community » Needs review
FileSize
503 bytes

@catch,

Uploaded patch in 8.4.x with required change.
Please review.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

@chiranjeeb2410, you just posted the same patch from #13. Please don't post the same patch anymore.

chiranjeeb2410’s picture

Status: Reviewed & tested by the community » Needs review

@claudiu.cristea,

My bad there, thanks anyways.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

@chiranjeeb2410, this was RTBCed by me. Please stop changing the status.

  • catch committed 78adae8 on 8.4.x
    Issue #2640668 by sathish.redcrackle, chiranjeeb2410, shashikant_chauhan...
catch’s picture

Committed/pushed both the patches to 8.4.x and 8.3.x respectively.

  • catch committed 43a6759 on 8.3.x
    Issue #2640668 by sathish.redcrackle, shashikant_chauhan, claudiu....
star-szr’s picture

Assigned: chiranjeeb2410 » Unassigned
Status: Reviewed & tested by the community » Fixed

Marking as fixed :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.