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:

  1. Comment: Media -> the media attached to comment, an image or video or audio (I'm using the media module)
  2. Comment: Title -> the comment title
  3. (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:

  1. my view title (eg: "[title] gallery")
  2. 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.

Comments

mxt’s picture

Issue summary: View changes

Minor adjustment

lunk rat’s picture

Title: "Use replacement tokens from the first row" doesn't work in "No results behavior" -> "Global: text area" » "Use replacement tokens from the first row" doesn't apply to "No results behavior" -> "Global: text area"
Version: 7.x-3.5 » 7.x-3.7
Component: comment data » Code
Category: bug » task

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

lunk rat’s picture

Issue summary: View changes

where -> when

jwineichen’s picture

Thanks for the workaround!

nwom’s picture

Version: 7.x-3.7 » 7.x-3.x-dev

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

ayesh’s picture

Status: Active » Needs review
StatusFileSize
new659 bytes

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

marko b’s picture

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

andres.torres’s picture

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

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 2 year old patch in #4 to views_handler_area_text.inc does not apply to the latest views 7.x-3.x-dev.

Checking patch handlers/views_handler_area_text.inc...
error: while searching for:
      '#wysiwyg' => FALSE,
    );

    // @TODO: Refactor token handling into a base class.
    $form['tokenize'] = array(
      '#type' => 'checkbox',

error: patch failed: handlers/views_handler_area_text.inc:31
error: handlers/views_handler_area_text.inc: patch does not apply
Snehal Brahmbhatt’s picture

Status: Needs work » Needs review
StatusFileSize
new671 bytes

@Chris Matthews, Please review this attached rerolled patch as per the current branch

damienmckenna’s picture

Issue tags: -Needs reroll