Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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');
}
}
}
Comment | File | Size | Author |
---|---|---|---|
reaction.txt | 548 bytes | iamjon | |
mymodule.txt | 1.21 KB | iamjon | |
context1.jpg | 243.02 KB | iamjon |
Comments
Comment #1
iamjon CreditAttribution: iamjon commentedJust to clarify context_active_contexts() is supposed to give an array with the context objects.