backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

Provide chained term tokens for taxonomy_term_reference fields #2949

Open juanolalla opened 6 years ago

juanolalla commented 6 years ago

The Entity Token submodule for Drupal 7 provides support for chained tokens, so they can be used with entities referenced by fields. However, Backdrop's implementation of entity_token is very simple and doesn't include that, only chained url and original tokens are included.

This whole feature has been already requested in https://github.com/backdrop/backdrop-issues/issues/1440. However, that doesn't seem a straight-foward implementation. It's relying a lot on Drupal 7 Entity functions, such as entity wrappers and other utilities Backdrop doesn't have, or use the same way.

My approach here would be to start providing something simpler and more widely used, a taxonomy term reference field chained token.

For example, we can use the parents path in an alias pattern [node:_field_taxonomy_term_:parents:join-path]. We can provide this from the Field module.

jenlampton commented 5 years ago

I'm using chained term tokens on 4 live sites, and the patch is working great. On newer versions of PHP I do get a PHP notice:

Notice: Undefined index: field_type in field_token_info_alter() (line 41 of backdrop/core/modules/field/field.tokens.inc).

I'm going to push a new PR that resolves this warning.

ghost commented 4 years ago

I tested this and, while it does indeed work, it seems to provide additional tokens that shouldn't be there (i.e. they don't work). Here's my scenario:

I have a content type (Species) that references a vocabulary (Genus). Genus then references another vocab (Family), which in turn references another vocab (Order) which in turn references another vocab (Group). Here's a diagram to explain:

Diagram

What I needed was a token in my Species node that output the Group name (by following the chain down through the different vocabularies). This is the token that worked in D7 and which works in Backdrop thanks to this PR: [node:field_genus:field_family:field_order:field_group]

However, when I was looking through the various tokens, I saw tokens like this: [node:field_genus:field_group] and [node:field_genus:field_order] These shouldn't be possible, as there's no direct link between Genus and Group or Order. So I think this is where the PR needs work, to avoid creating tokens that don't actually work...

jenlampton commented 2 years ago

These shouldn't be possible, as there's no direct link between Genus and Group or Order. So I think this is where the PR needs work, to avoid creating tokens that don't actually work...

This is a problem with tokens in general, and I don't think there's anything I can change about this PR to fix it.

There is no way to request all available tokens for a single node type, or a single vocabulary. That means when generating lists of available tokens for a vocabulary, the system shows you all available tokens for all vocabularies.

I can't even go in later and alter out the ones that shouldn't be there because there's no bundle information there at all to compare against.

edit: this can't be right....

jenlampton commented 2 years ago

I rebased and reworked the PR to put the taxonomy-specific tokens into taxonomy module (instead of field module) but I think the token bundle problem will need to be solved separately, perhaps in the user-interface for token browser.