How can I set a View contextual filter fallback? Ok I have 2 content-types:


Page
Video


I have a block in the sidebar that shows videos embed by youtube.

In the Video content-type, I have a Node References field that can reference any Page-type node.

I would like to set up the sidebar block View so that it can output a random video-type tagged with the current page-type node, however if there are no video-type nodes referencing the current page, or if the current page is not a page-type node, then it would select ONLY  video-type nodes that are either (depending on what is simpler to implement):


Have another field on the video-type which can tag the node as "global" (this would be preferable)
OR Not referencing any page-type nodes


I was hoping to try and make use of the Context module, but I'm wondering whether the module is quite so granular or conditional?

Thanks!
Ok, decided to write my own context condition plugin for this, all in a single file for a custom module that would be called custom_context:

function custom_context_context_registry() {
  $registry = array(
    'conditions' =&gt; array(
      'views_result' =&gt; array(
        'title' =&gt; t('Views Results'),
        'description' =&gt; t('Set this context when one of these views returns a result.'),
        'plugin' =&gt; 'custom_context_condition_views_result',
      )
    )
  );
  return $registry;
}

function custom_context_context_plugins() {
  $plugins = array();
  $plugins['custom_context_condition_views_result'] = array(
    'handler' =&gt; array(
      'class' =&gt; 'custom_context_condition_views_result',
      'parent' =&gt; 'context_condition',
    ),
  );
  return $plugins;
}

function custom_context_init(){
  if ($plugin = context_get_plugin('condition', 'views_result')) {
    $plugin-&gt;execute();
  }
}

class custom_context_condition_views_result extends context_condition {

  /**
   * Generate a list of database and module provided views.
   */
  function condition_values() {
    $enabled_views = array();

    $views = views_get_all_views();
    ksort($views);

    foreach ($views as $view) {
      if (!isset($views[$view-&gt;name]-&gt;disabled) || !$views[$view-&gt;name]-&gt;disabled) {
        $displays = array();
        foreach ($view-&gt;display as $id =&gt; $display) {
          $displays[$view-&gt;name . ":" . $id] = check_plain("{$view-&gt;name} : {$display-&gt;display_title}");
        }
        $enabled_views += $displays;
      }
    }
    return $enabled_views;
  }

  function execute() {

    $view_name_displays = array();

    // Gather all required views for checking, to prevent duplicate checking
    foreach ($this-&gt;get_contexts() as $context) {
      foreach ($context-&gt;conditions['views_result']['values'] as $view_name_display){
        $view_name_displays[$view_name_display] = $view_name_display;
      }
    }

    foreach($view_name_displays as $view_name_display){
      list($view_name, $view_display) = explode(':',$view_name_display);
      $view = views_get_view($view_name);
      $view-&gt;set_display($view_display);
      $view-&gt;build();
      $view-&gt;execute($view-&gt;current_display);
      if(count($view-&gt;result)){
        foreach ($this-&gt;get_contexts($view_name_display) as $context) {
          $this-&gt;condition_met($context, $view_name_display);
        }
      }
    }
  }
}


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.