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' => array(
'views_result' => array(
'title' => t('Views Results'),
'description' => t('Set this context when one of these views returns a result.'),
'plugin' => 'custom_context_condition_views_result',
)
)
);
return $registry;
}
function custom_context_context_plugins() {
$plugins = array();
$plugins['custom_context_condition_views_result'] = array(
'handler' => array(
'class' => 'custom_context_condition_views_result',
'parent' => 'context_condition',
),
);
return $plugins;
}
function custom_context_init(){
if ($plugin = context_get_plugin('condition', 'views_result')) {
$plugin->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->name]->disabled) || !$views[$view->name]->disabled) {
$displays = array();
foreach ($view->display as $id => $display) {
$displays[$view->name . ":" . $id] = check_plain("{$view->name} : {$display->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->get_contexts() as $context) {
foreach ($context->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->set_display($view_display);
$view->build();
$view->execute($view->current_display);
if(count($view->result)){
foreach ($this->get_contexts($view_name_display) as $context) {
$this->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.