Problem/Motivation
Use case: Get all nids of referenced node, like:
[node:field_ref:all:nid]
This is not possible right now.
(Remember: [node:field_ref] will give us a comma-separated list of titles.)
Also other properties should be possible like:
[node:field_ref:all:vid]
[node:field_ref:all:field-foo]
There are quite some ideas and approaches (see linked issues) to multivalue tokens.
As i see it none of them can handle this or be extended to do so.
The closest approach so far is the array token approach ("ref:join"). But this does not seem generalizable to arbitrary properties like stated above.
Proposed resolution
So we use a different syntax to be consistent and extensible:
* simplest example: [node:field_ref:all:nid]
* chaining possible, think of [node:field_ref:*:vid] or [node:field_ref:all:field_another_ref:all:nid]
* extended syntax to declare separator like [node:field_ref:all(s=+):nid]
(of course we can use other separators than brackets, it's all a question of unique parsing and escaping)
* above syntax is extensible, think of [node:field_ref:all(s=:):nid] and [node:field_ref:all(s=+)(condition=nid<100):nid]
(think of the list comprehensions metaphor)
Remaining tasks
Feedback, discuss, test, commit.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#8 | entity-2401313-8-List-comprehension-tokens-like-ref-all.patch | 2.54 KB | Nikita Petrov |
| |||
#5 | entity-2401313-5-List-comprehension-tokens-like-ref-all.patch | 2.58 KB | geek-merlin |
Comments
Comment #1
geek-merlinComment #2
geek-merlinComment #3
geek-merlinComment #4
geek-merlinComment #5
geek-merlinI think i was too bold using '*' special character as token.
If we are conservative and use 'all', panels placeholders (and maybo others) will pick us up too.
Comment #6
tregismoreira CreditAttribution: tregismoreira commentedHey @axel.rutz, thanks for your contribution. The patch #5 worked fine for me!
Maintainers, any plan for this patch to be released?
Comment #7
geek-merlinNice that this is useful to you!
Comment #8
Nikita Petrov CreditAttribution: Nikita Petrov commentedThe patch #5 works great when we need a simple wildcard, used 'all', comma separated. I tried to make extended sintax work, but with no luck (I tried to use a chained example [node:field_ref:all(s=+):nid]). The '+' sign is the second common use case when we need to pass those nids with OR statement (instead of AND statement which applies to comma separated values). (s=+) parameter just was stripped out somewhere deep in token module and I was not able to trace it. Here is a temporary solution for those who needs '+' separated values.
Comment #9
vaccinemedia CreditAttribution: vaccinemedia at CTI Digital commentedThis patch fixed an issue I had yesterday which I wasted 5 hours on where I have an EVA view and an entity reference field on a paragraph bundle and needed to have a contextual filter for all nodes which have the same value(s) as the paragraph the view is embedded on.
Passing the entity (term) reference token on it's own as [paragraphs_item:field-team] did not work (although the args were tids separated by commas using xdebug but then became the parent node ID as soon as I added a contextual filter... bizarre) but passing [paragraphs_item:field-team:all:tid] (field team being the entity reference field and "team" being a taxonomy vocabulary) after applying this patch did the trick.
I can say that this is reviewed still - any chance we can get this committed? It could have saved me a lot of time yesterday and head desk banging ;)