Hi
I have a context that is derived from the active menu item. I have a three reactions. The first, theme, provides a variable, the second debug alerts the current condition and the third from my module get's a blank array context_active_contexts().
Code in body and attached. Screenshots attached.

I'm using menu breadcrumbs to set the active trail.

The menu is multilingual


/**
 * Implementation of hook_init().
 */
function mymodule_init() {
  $plugin = context_get_plugin('reaction', 'mymodule_form');
    if ($plugin) {     
    $plugin->execute();
  }
}


/**
 * Implementation of hook_context_registry().
 */
function mymodule_context_registry() {
   return array(
    'reactions' => array(
      'mymodule_form' => array(
        'title' => t('Care Form'),
        'description' => t('This plugin is supposed to change the value of the form when exectuted'),
        'plugin' => 'mymodule_form_context_reaction',
      ),
    ),
  );
}

/**
 * Implementation of hook_ctools_plugin_api().
 */
function mymodule_ctools_plugin_api($module, $api) {
  if ($module == 'context' && $api == 'plugins') {
    return array('version' => 3);
  }
}



/**
 * Implementation of hook_context_plugins().
 */
function mymodule_context_plugins() {
  $plugins = array();
  $plugins['mymodule_form_context_reaction'] = array(
    'handler' => array(
      'path' => CAREPATH .'/plugins',
      'file' => 'mymodule_form_context_reaction.inc',
      'class' => 'mymodule_form_context_reaction',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}



/**
 * Implemenation of hook_reaction
 */
class mymodule_form_context_reaction extends context_reaction {
 function options_form($context) {
     return array('test' => array('#type' => 'value', '#value' => TRUE));
   }
  function options_form_submit($values) {
    return array('test' => 1);
  }
  /**
   * Output a list of active contexts.
   */
  function execute() {
  
  $contexts = context_active_contexts();
   if(empty($contexts)){
     drupal_set_message('contexts is empty');
    }
    
   
   
  }   
   
}

CommentFileSizeAuthor
reaction.txt548 bytesiamjon
mymodule.txt1.21 KBiamjon
context1.jpg243.02 KBiamjon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iamjon’s picture

Just to clarify context_active_contexts() is supposed to give an array with the context objects.