I have a taxonomy reference field with multible and hierarchical terms selected. The token [term:field-taxonomy_ref_field]
is giving me the term title with leading dashes dependent on the term hierarchy. These dashes shouldn't be there.
For a vocabulary like this:
term_lvl1
term_lvl2-01 (selected)
term_lvl2-02 (selected)
term_lvl3-01 (selected)
I get a value of this: -term_lvl2-01, -term_lvl2-02, --term_lvl3-01
.
This seems also to depend on the kind of select widget you can use.
For checkbox, select field, or term reference tree (contrib module) I get a term name in the form of: -termname
or --termname
with dashes in front of the name (depending on the hierarchy level of the term).
For the autocomplete term widget (tagging) I get the correct term string like: termname
.
If I use the token of the token module (with underscore) [term:field_taxonomy_ref_field]
the correct values are returned term_lvl2-01, term_lvl2-02, term_lvl3-01
.
So this has to be an entity token bug. I tried to debug into the code where the values are pulled but get lost somewhere in the (somewhat confusing) code.
So maybe someone more experienced with entity and token can help out.
Comment | File | Size | Author |
---|---|---|---|
#1 | entity_wrapper.inc label().png | 141.99 KB | marcelovani |
#1 | View the node.png | 40.54 KB | marcelovani |
#1 | Add token to body.png | 46.43 KB | marcelovani |
#1 | Input filter - Replace tokens.png | 78.08 KB | marcelovani |
#1 | Term reference - Unlimited values.png | 81.26 KB | marcelovani |
Comments
Comment #1
marcelovaniThis issue was opened 2 years ago, but the actual problem started back in 2010 https://www.drupal.org/node/1005532
I wonder how not many people is following this issue.
Here are my findings.
How to replicate the problem
How to stop the problem
Edit entity.wrapper.inc
I added a return here and that seems to fix the problem, but I wonder what does that code actually do and why it was introduced in https://www.drupal.org/node/1005532
I understand adding the hyphens on the CMS, when you are editing the node, but these hyphens should not be present on the front end.
Comment #2
marcelovaniUpdate: Not sure if I did something wrong when I added these steps or I am doing something wrong now, but I am no longer able to reproduce the problem.
Comment #3
quotesBro CreditAttribution: quotesBro commentedConfirming: when using token with underscore (e.g. [term:field_taxonomy_ref_field]), the correct label is returned.
When using token with hyphen (minus sign) (e.g. [term:field-taxonomy-ref-field]), label for the child term starts with a minus.
Comment #4
quotesBro CreditAttribution: quotesBro commentedComment #5
quotesBro CreditAttribution: quotesBro commentedThe problem is
$node_entity_wrapper->field_taxonomy_term_reference
instantiates EntityListWrapper, and its label generation viaoptionsList
invokestaxonomy_allowed_values
, that loads the full taxonomy vocabulary tree with depth and adds leading dash for each level of term depth.The Token module, on the other hand, implements field_tokens(), so the specific field value is used as a replacement.
Comment #6
quotesBro CreditAttribution: quotesBro commentedComment #7
quotesBro CreditAttribution: quotesBro commentedClosing as duplicate of https://www.drupal.org/project/entity/issues/1107396