Hi all,
I have a website where user can attach media files to their comments.
I've created a view to show all the media files attached to comments of a node.
In this view (base table = comment) I retrieve the following fields:
- Comment: Media -> the media attached to comment, an image or video or audio (I'm using the media module)
- Comment: Title -> the comment title
- (Content) Content: Title -> the node title (obtained with a relationship to node table. The node obviously is that one which comments are attached to)
Last field is "excluded from display" because I use this only as token replacement [title] in:
- my view title (eg: "[title] gallery")
- and in my "No results behavior" -> "Global: text area" (e.g. "No media files exists for [title]").
All works fine, title token replacement works correctly, but only if there are results.
The issues is triggered when the view returns no results: in this case the "No results behavior" -> "Global: text area" text is shown, but [title] token replacement doesn't work (in the view title also)
As actual workaround I have to:
1) turn php filter on for "No results behavior" -> "Global: text area"
2) put the following code to retrieve the node title:
<?php
$view = views_get_current_view();
$node = node_load( $view->args[0] ); // the node id
$title = $node->title;
$view->build_info['title'] = $title . ': Gallery';
?>
<p>No media files exists for <?php print $title; ?>.</p>
<p>Would you like to be the first to upload an image, a video or an audio regarding <?php print $title; ?>?</p>
<p><big><strong>Write a comment and attach the media file to it!</strong></big></p>
Thank you for working on this.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | views-1895724-81.patch | 671 bytes | Snehal Brahmbhatt |
| #4 | views-1895724-4-hide-tokens-in-empty-results.patch | 659 bytes | ayesh |
Comments
Comment #0.0
mxtMinor adjustment
Comment #1
lunk rat commentedChanging this from the original issue because it stems from a confusing and impossible option available in no results behavior:
Replacement tokens from first row should not be available anywhere within No results behavior because there is no first row (it is "no results" behavior after all!). There can never be tokens where there are no results.
It seems to me that for usability purposes all options regarding replacement tokens should be suppressed from the no results behavior dialog.
Comment #1.0
lunk rat commentedwhere -> when
Comment #2
jwineichen commentedThanks for the workaround!
Comment #3
nwom commentedThis also applies to "Views headers/footers -> Global: Text areas" as well.
Currently it is only possible to use Replacement Patterns if the view contains at least one row, even though the replacement patterns could still technically be used. It would still be useful, when wanting to use data from relationships of the contextual filter as an example. Since the contextual filter, could contain a node and have a relationship with a specific entity.
Comment #4
ayesh commentedHere is patch that returns the form array in option_form callback before adding token options to the form, if the handler is used in empty results list. I'd be grateful if anyone could review.
Thanks.
Comment #5
marko b commentedMakes sense, patch looks good. only thing is that I would really have good use of tokens in that no result block, for example to use user id from current page. But I guess preprocessing is the way here.
Comment #6
andres.torres commentedsame issue is present on a fresh Drupal 8.3 install. after creating a new view, and attempt to add the content from an excluded field on the Header area of the view by checkin the replacement tokens option, does not work at all.
Comment #7
chris matthews commentedThe 2 year old patch in #4 to views_handler_area_text.inc does not apply to the latest views 7.x-3.x-dev.
Comment #8
Snehal Brahmbhatt commented@Chris Matthews, Please review this attached rerolled patch as per the current branch
Comment #9
damienmckenna