Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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"
}
Comment | File | Size | Author |
---|---|---|---|
#16 | 2640668-10.patch | 503 bytes | chiranjeeb2410 |
#13 | 2640668-10.patch | 503 bytes | sathish.redcrackle |
#9 | 2640668-9.patch | 477 bytes | shashikant_chauhan |
Comments
Comment #2
MichelleLooks like this was caught in the spam trap. Publishing.
Comment #3
swentel CreditAttribution: swentel as a volunteer commentedVocabularies 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.
Comment #7
claudiu.cristeaYes, it should return the ID which is a "machine name". Vocabularies are config entities with the ID as string.
Comment #8
iMiksuThe point is not "ID", the point is "integer", see the current code from 8.3.x head:
This was confusing to me also. The docs are misleading and needs to be fixed.
Comment #9
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedAdding patch.
Comment #10
claudiu.cristeaThis is already deprecated in 8.4.x (see http://cgit.drupalcode.org/drupal/tree/core/modules/taxonomy/src/TermInt...). Probably will need a port?
Comment #11
claudiu.cristeaFixing title as per #8 and reverted to 8.3.x
Comment #12
catchEven 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
Comment #13
sathish.redcrackle CreditAttribution: sathish.redcrackle at Red Crackle commentedre-roll for 8.4.x
Comment #14
sathish.redcrackle CreditAttribution: sathish.redcrackle at Red Crackle commentedComment #15
claudiu.cristeaBack 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.
Comment #16
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@catch,
Uploaded patch in 8.4.x with required change.
Please review.
Comment #17
claudiu.cristea@chiranjeeb2410, you just posted the same patch from #13. Please don't post the same patch anymore.
Comment #18
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commented@claudiu.cristea,
My bad there, thanks anyways.
Comment #19
claudiu.cristea@chiranjeeb2410, this was RTBCed by me. Please stop changing the status.
Comment #21
catchCommitted/pushed both the patches to 8.4.x and 8.3.x respectively.
Comment #23
star-szrMarking as fixed :)