1

I'd like to give users the option to create new content when a certain contextual filter is missing on a panel.

e.g. I have my reviews on a panel. When a review is missing I'd like it to display a block/link to submit a new review.

However my only options are to hide the view, give a summary etc.

How do I do this?

I've found the option for 'No Results Behaviour', but I can't hook into the contextual filter (and then use a relationship to grab a term name). I've also found this work around:

https://www.drupal.org/node/1895724

But I'm struggling to re-write the code to pull the term name out of the term id in the contextual filter.

2 Answers 2

1

Here I suppose you have added an argument in panel path. You can assign any context to your argument, eg Node: Id. It can be Term as well.

enter image description here

Assign any context to argument like :

enter image description here

Add a visibility rule if Context exists to your view and not exists to custom pane.

enter image description here

8
  • Sumit I don't really follow. I'm looking at this from the point of view of the ... View. Yes I have an argument from the panel, but I don't follow you after that. Did you read the question I linked? Commented Dec 11, 2014 at 14:47
  • So you're saying, "If the argument doesn't exist, skip calling the view", right? That can work in some cases, but say you're checking, "has something been tagged with this term", then the term argument always exists, so this won't help. Do I understand that right?
    – Letharion
    Commented Dec 11, 2014 at 14:56
  • Well thats correct @Letharion.. In the case you said Views No Result Behaviour will work. :) Commented Dec 11, 2014 at 14:59
  • @SumitMadan I may have been confusing this with another question I was looking at recently. Reading the question again it looks like this would be a good solution.
    – Letharion
    Commented Dec 11, 2014 at 15:00
  • I don't think this works as I don't have a node id in that scope. I'm passing it as a value on a link from one view to the next. Does this still work? Commented Dec 11, 2014 at 15:00
0

I managed to work it out, I turned on the PHP Filtering module, and inserted this as a Global text area, with Text format = PHP Code

<?php
    $view = views_get_current_view(); //get the current view
    $term =  taxonomy_term_load( $view->args[0] ); // the term id
    $term_name = taxonomy_term_title($term); //get the term id e.g. turn 123 = term_name
?>
<p>No comments exist for <?php print $term_name; ?>.</p>//print out the name
<p><a class="button" href="localhost/drupal/node/add/technology-comments?edit[field_technology][und][textfield]=<?php print $term_name; ?>">Add new comment</a> </p> //link to the add new page, pre-populating with term_name
<p></p>
2
  • Well if Its just about the Term Name in pane, I suggest you should create a ctool plugin rather than adding php code inside database. Commented Dec 11, 2014 at 15:57
  • Thanks, @SumitMadan I'll look into it. This looks like a good place to start? Commented Dec 11, 2014 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.