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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geek-merlin’s picture

Title: List comprehension tokens like ref:?:nid » List comprehension tokens like ref:*:nid
Status: Active » Needs review
FileSize
2.57 KB
geek-merlin’s picture

Issue summary: View changes
geek-merlin’s picture

Issue summary: View changes
geek-merlin’s picture

geek-merlin’s picture

Title: List comprehension tokens like ref:*:nid » List comprehension tokens like ref:all:nid
Issue summary: View changes
FileSize
2.58 KB

I 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.

tregismoreira’s picture

Status: Needs review » Reviewed & tested by the community

Hey @axel.rutz, thanks for your contribution. The patch #5 worked fine for me!

Maintainers, any plan for this patch to be released?

geek-merlin’s picture

Nice that this is useful to you!

Nikita Petrov’s picture

The 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.

vaccinemedia’s picture

This 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 ;)