Problem/Motivation

I want to access views arguments as tokens within a view. For this i have created a single view of articles with a path: articles/% and added a contextual filter for content ID.

None of the [view:url:subfield] arguments render correctly neither in a view row (in the article itself) nor from a global text header added to the view.

To test I have directly copied the list provided by token_filter and pasted the same into (i) an article and (ii) a global text header within a view. I then list the article in a view with a contextual filter applied to see if the tokens render in the view, but they do not. The only token that renders correctly is the [view:url] in the view text header.

URL [view:url]
Absolute URL [view:url:absolute]
Arguments [view:url:arg:1] 
Count [view:url:args:count]
First [view:url:args:first]
Keys [view:url:args:keys]
Last [view:url:args:last]
Reversed [view:url:args:reversed]
Value [view:url:args:value:1]

Steps to reproduce

- install and enable token and token_filter modules and ensure that token_filter is enabled on basic and full page editors.
- create an article with the list of view tokens shown above
- create a page view to list articles
- set page view path = /articles/%/%
- add a global text header with view tokens shown above
- view the rendered output
- note that the only field that renders is the view:url in the global text header. no other tokens in either the view header text or the view row render as expected

actual output from the view @ /articles/[articleid]

This is the views global text header

note: none of the view:url:subfield tokens render correctly

URL http://drupal896.syntapse.co.uk/articles/76
Absolute URL [view:url:absolute]
Arguments [view:url:arg:1] 
Count [view:url:args:count]
First [view:url:args:first]
Keys [view:url:args:keys]
Last [view:url:args:last]
Reversed [view:url:args:reversed]
Value [view:url:args:value:1]

This is the article body rendered as a view row

note: none of the view:url tokens render correctly

URL [view:url]
Absolute URL [view:url:absolute]
Arguments [view:url:arg:1] 
Count [view:url:args:count]
First [view:url:args:first]
Keys [view:url:args:keys]
Last [view:url:args:last]
Reversed [view:url:args:reversed]
Value [view:url:args:value:1]

Proposed resolution

I was expecting the [view:url] and [view:url:subfields] to render both in the global view header text and in the article when rendered as a view row. Only the [view:url] is working in the view header text and no other tokens render correctly.

Unless documented otherwise the user should expect both of these outputs to render correctly and completely.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Syntapse created an issue. See original summary.

Syntapse’s picture

Issue summary: View changes
Syntapse’s picture

Issue summary: View changes
Syntapse’s picture

Issue summary: View changes
darvanen’s picture

Status: Active » Postponed (maintainer needs more info)

@Syntapse have you tried any of those tokens in a regular text field?

This module only extends core and the token module behaviours to include text_area fields.

If you can get the tokens to work in a normal text field and they still don't work in a text_area field, then it's something this module needs to investigate.

Syntapse’s picture

Thanks just to clarify: are the two view elements i mention - view global header text and a views row text field - not supported by design?

When you say "normal text field" do you mean a field on a node listed as a view row field? If so I think the context is incorrect as these items only make sense within a context of a view, not a node/entity.

It would be super useful to have these work with view's native text fields, not the entities.

I hope I am interpreting you correctly, and my reply makes sense.

Thanks

darvanen’s picture

Priority: Major » Normal
Status: Postponed (maintainer needs more info) » Active

@Syntapse this module does not perform any of the logic around token replacement, it only applies the logic supplied by core and the token module to a different kind of field: text_area.

That being said, it's possible the hook this module uses to add that logic is not triggered by views. I'm not convinced this module is to blame yet.

Happy to review patches.

leeksoup’s picture

Having the same problem. Views Header is a text area, and allows the use of content filters. I added the token filter provided by this module to my Filtered HTML configuration. Then I put the token [view:url:arg:1] as part of a context-based link in the header. This does not work.

But [view:url] does work, as OP stated. The available tokens list (in the Views header edit) does not include any of the view: tokens and I could not find any documentation.

Thanks.

darvanen’s picture

Status: Active » Closed (works as designed)

Thanks for the clarification! If the filter provided by this module replaces some tokens but not others in the same location, this issue is out of scope for this module.

Perhaps try the new context_stack project.

Also, if you're trying to pull an argument from the URL the user has visited, I don't think [view] is the right token type to use, I suspect [view:url] is about the setting, not the value.

I'm going to close this as "works as designed" but I'm happy to reopen it if the problem can be demonstrated to be part of this module.