The purpose of this is related to my question on DA: http://drupal.stackexchange.com/questions/13417/how-can-i-set-a-view-con...
I would love to be able to set a context based on how many rows a View is returning. For instance in my example, I would like to display all videos attached to a node, unless the current node is not attached to any videos, in which case it would output all videos flagged as global.
This could easily be 2 separate view displays (node_videos and global_videos), and then have Context module set a context based on the number of rows node_videos returns.
EDIT: Also, could this use something related to how VBO hooks into Rules? VBO provides a condition such as "Check the number of results returned by a View"
Comments
Comment #1
carn1x CreditAttribution: carn1x commentedOk, decided to write my own context condition plugin for this, all in a single file for now:
Just to explain how this works, it loads all the views which context module should check on hook_init and checks whether each view has rows or not. I've combined this with certain views which obtain their contextual filters from the current node ID.
Comment #2
carn1x CreditAttribution: carn1x commentedI guess I'll set this to needs review in case the maintainers or anybody feels like this might be worth integrating.
Comment #3
broeker CreditAttribution: broeker commentedI used this as the basis for a custom module to solve a particular use case -- still works like a charm on latest dev, and it seems generic enough that it would make a nice official plugin to context if there are enough people with similar use cases. Ours involved setting a context based on whether nodes of a certain type existed within an Organic Group but I can think of several other places it would be useful to set context based on the results of a views.
Comment #4
jpstrikesback CreditAttribution: jpstrikesback commentedThanks @carn1x here is a version I placed in a sandbox that uses hook_views_post_execute() instead of hook_init so as to only be executed when a view is executed. That wouldn't work for a global type of condition but it works for checking the results of a view that is just about to be rendered.
Views Result Context
Comment #4.0
jpstrikesback CreditAttribution: jpstrikesback commentedadditional
Comment #5
kevinquillen CreditAttribution: kevinquillen at Velir commentedhttps://www.drupal.org/project/views_minimum