Is this not possible as it was in Drupal 7 to convert taxonomy terms in the URL to their ID?

See this post on Stackexchange: http://drupal.stackexchange.com/questions/174251/taxonomy-term-name-as-c...

I try "Content: Has taxonomy term ID" and set the validator to "term name", but when I try to put in "term name" as a validator and use the term name in the preview box, it looks like it's trying to use the 'tid' field of the taxonomy_index table with the textual value of the term:

WHERE (( (taxonomy_index.tid = 'Discussion') )AND

When I try to use the TID, I just get a 'no query was run' message and nothing is returned.

Comments

Anonymous’s picture

toddmbloom created an issue. See original summary.

webiator GmbH’s picture

Hello toddmbloom,

I also have been looking for this functionality for quite some time now. Ended up creating a reference to taxonomy terms referenced by content and then adding a contextual filter "term name".

If you do that then the validator will work. However you cannot have term names with slashes "/" or any other special characters.

Hope that helps,

Regards
/B

Anonymous’s picture

Ah ha, this was great.

For the record, creating a relationship with "Taxonomy terms on node" and configuring it to pull from the taxonomy you want to filter on from the URL will allow you to create a contextual filter using the term relationship for Taxonomy term: Name.

webiator GmbH’s picture

Only problem is that this does not work with term names which consist of more than letters and spaces.

Example:
A term name like "Management / Consulting" would not work because views would need "management-/-consulting" as contextual filter to map correctly ... :/

Any ideas on this one?

Berdir’s picture

Consider generating aliases for your terms instead and work with the ID's internally. Will require custom code but not too much.

webiator GmbH’s picture

@Berdir:

I tried that already and this would mean that I have to use the core taxonomy view. Since pathauto cannot generate taxonomy term aliases if its pattern equals a view path.

Or am I missunderstanding something?

Berdir’s picture

As I said, you can use your own code to create aliases, the API is not that complicated to use:

\Drupal::service('path.alias_storage')->save($source, $alias);

You could also look into page_manager. It has the advantage that you can have variants that apply to just to terms of a specific vocabulary and have a different view/blocks for that.

Olafski’s picture

For curiosity: Does anybody know why the Filter value type "Term name converted to term ID" option was removed in Views 8? It was really helpful for site builders.

calefilm’s picture

For anyone running into the same problem I had... I kept searching through the Titles in Contextual Filters, lokoing for "Taxonomy Name" ... Just as "Taxonomy Term ID" is labeled correctly etc.... Instead, search for "Name" and you will find what you're looking for.

keithm’s picture

@calefilm this was very helpful.
Also see https://drupal.stackexchange.com/a/201215/2272

brianwagner’s picture

@calefilm is right on. Search for 'Name' to get taxonomy term name. Because it doesn't show up when you search for 'taxonomy'.

yuseferi’s picture

Use https://www.drupal.org/project/views_taxonomy_term_name_depth module, it works correctly and let you filter (contextual filter) result according to term name.

iyyappan.govind’s picture

@zhilevan,I have installed views_taxonomy_term_name_depth module but I can not see the that field in taxonomy term view.

Please help me

Thanks

rayorg’s picture

"views_taxonomy_term_name_depth", or any other ones, does not work for me under any combination. That filter was very handy, why was it removed? Can it be added back?

Thanks!

sourabhutani’s picture

Is there anybody solved this issue for taxonomies names having spaces and dashes in name ? Drupal module Views Taxonomy Term Name Depth is not solving this.

komejo’s picture

For anyone else running into this issue, the simplest process at this time seems to be adding the relationship as mentioned in #3, then the https://www.drupal.org/project/views_taxonomy_term_name_depth plugin, and use the relationship with it. The plugin has a working implementation of the taxonomy term name from URL, even with dashes in the term.

seizethecarp’s picture

For anyone else like me looking for how to make it work, I Gumped my way into my into success partly following: http://redcrackle.com/blog/adding-contextual-filter-view-drupal-8

I'm using Drupal 8 and Zircon. I'm brand new so I may use the wrong terms.
I wanted to make contextual images in "Panel first col 1" based on the Category of the page that someone is on.
What I did was go to Structure > Views > Carousel (the view that has the pictures in that block region) > Advanced > Add by Contextual Filters > Has taxonomy term ID > select in Provide default value: Taxonomy term ID from URL (which made no sense to me but whatever) > then I checked all three boxes: Load default filter from term page, Load default filter from node page, that's good for related taxonomy blocks, Limit terms by vocabulary. Then for Vocabularies I checked Categories.

PHEW! Finally!
Thanks to you all on here for pointing me in the right direction!

Anonymous’s picture

I am unable to make this work.

I have a content type called ‘Event’ with an entity reference to the Taxonomy Vocabulary ‘Production.’

I have created a view called ‘Book Tickets’ and I’d like a contextual filter that finds events based on a Procduction Taxonomy term.

So the url for the view should be /book-tickets/term-name e.g. /book-tickets/steptoe-and-son.

Is this possible? Reading previous posts and trialling different settings I have yet been able to get it to work, except when using the terms ID.

drupalnesia’s picture

@TECreasey

  1. If you would like Taxonomy term with depth: then only Term ID works
  2. If you just use Taxonomy term without depth: then you use Term ID as usually but:
  3. When the filter value IS in the URL or a default is provided: Override title = {{ arguments.tid }}

{{ arguments.tid }} will convert Term Name to Term ID

This is D8 bug. The only solution right now is https://www.drupal.org/project/views_taxonomy_term_name_depth

cbfannin’s picture

@zhilevan recommendation in comment #12 worked for me! My relationship was already set up. My goal was to pull the first component from the URL to match up with a taxonomy term name as the contextual filter. The plugin allowed me to compare my path's component to the generated taxonomy term's name rather than the tid or Name as it was provided in my vocabulary list (i.e. the term "President's Office" became "presidents-office"). I set the contextual filter for WHEN THE FILTER VALUE IS NOT AVAILABLE Provide Default value > Type as Raw value from URL > Set my path component to 1 (in my case) and checked "use path alias". Now it works as expected. Thanks!

adamborecki’s picture

#12 also worked for me!

https://www.drupal.org/project/views_taxonomy_term_name_depth

That module solved the problem instantly, and the query works properly.

itchyeyeballs’s picture

The limitation with this (https://www.drupal.org/project/views_taxonomy_term_name_depth) module seems to be that you can't specify which vocabulary to use, we want to use a vocabulary called "categories" to filter the view but there is a risk of rogue content showing up in if someone happens to enter a duplicate entry in the "tags" vocabulary when tagging their article.

dww’s picture

Yeah, core is broken in this regard.

I just wrote https://www.drupal.org/project/views_taxonomy_term_name_into_id to restore the missing functionality.

imclean’s picture

@dww that looks very interesting. I wonder if a similar method could be used to reference existing taxonomy terms when creating content via REST. Or even creating new terms if they don't already exists. This feels like a generic problem in terms of taxonomy and entity references in general.

For example: #2771353: Support "auto-create" entity references by value (instead of by ID/UUID), just like tags are auto-created in the content creation UI

dww’s picture

Title: Taxonomy term name as contextual filter for view » Can't use a taxonomy term name as the value for a contextual filter in a view
Version: 8.0.1 » 8.5.x-dev
Related issues: +#2494617: TermName views argument_validator is not working as expected

@imclean: "Similar method" -- maybe. Same module -- no way. ;) This is a tiny module to provide a single piece of missing core functionality. It's not meant to be, and never will become, "fix everything wrong with core's handling of term names".module. Sorry.

Meanwhile, more appropriate version and better title.

imclean’s picture

@dww Ha yes, I do understand that. I just keep coming across lack of entity reference functionality when not specifically using a widget to create the reference. Just talking conceptually here, this module is sensibly quite focussed on the one task

DiDebru’s picture

#12 worked for me as well!

andyg5000’s picture

@dww thank you for creating `views_taxonomy_term_name_into_id`. Until this point, I've been joining the taxonomy tables to the view and filtering down that way, but that approach has it's own problems.

I think people are used to this option in D7 and expect it to be available in D8. Is there any reason or push back that lead you to create a separate module vs a patch?

ardnet’s picture

Hi all, solution #12 working for me, but is there any way to assign this to multiple terms?

dww’s picture

I had an urgent need, so I solved it in the quickest but most stable way I that I could share. In this case, it was a simple contrib module. I'm still in favor of a plan to fix all this in core itself. I don't have the time / bandwidth to spearhead that effort right now, find the most appropriate meta issue, update the summaries as appropriate, start rolling patch(es), etc. If someone else wants to run with that, I'll chip in when/where I can.

Thanks/sorry,
-Derek

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

Gung Wang’s picture

None of above solutions works on my site.
There is a table named taxonomy_term_field_data_node_field_data
in this Views Query below. However, there is no such table in my Drupal 8 database.
Instead, the exact names of tables about taxonomy are:

taxonomy_index	
taxonomy_term_data	
taxonomy_term_field_data	
taxonomy_term_hierarchy

Drupal Views Query:

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, taxonomy_term_field_data_node_field_data.tid AS taxonomy_term_field_data_node_field_data_tid
FROM 
{node_field_data} node_field_data
LEFT JOIN (SELECT td.*, tn.nid AS nid
FROM 
{taxonomy_term_field_data} td
LEFT JOIN {taxonomy_index} tn ON tn.tid = td.tid
WHERE td.vid IN ('faq_categories')) taxonomy_term_field_data_node_field_data ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid
WHERE ((taxonomy_term_field_data_node_field_data.name = 'consumer-life')) AND (node_field_data.type IN ('faq_question'))
ORDER BY node_field_data_created ASC
LIMIT 21 OFFSET 0

I figured it out: all our faq_question contents are unpublished, so it always shows nothing in the View.

Pascal-’s picture

Status: Active » Closed (works as designed)

I'm settings this to works as desgined, since the solution suggested in #2 and further explained in #3 worked for me.
There's also a workaround in #12 as confirmed by multiple replies.

angelg’s picture

I was experiencing a weird situation with REST views and contextual filters.

I will explain it on this thread because I found the solution here.

I had a contextual filter receiving the Taxonomy Name and then validating with 'Taxonomy Term Name' validator. Also, the filter has a relation to the specific field in the node (the one with the entity reference to the taxonomy vocabulary). But this wasn't working for all the terms of the vocabulary, some of them just show 'no query was run' message and nothing were returned. (it's like the terms were not passing the validation, but they exist on the vocabulary.)

I was just almost ending the development sprint and need to set up a solution, so following the idea from #19 (perhaps that the taxo term wasn't depth)

If you would like Taxonomy term with depth: then only Term ID works

and combining it with the awesome module from @dww

So I ended up using a contextual filter based on Term ID and using the validator "Taxonomy Term Name as ID" with the specific vocabulary. Everything works great!

Thanks guys!