Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I've tried creating own reaction on various conditions, but after spending whole day on it, it still doesn't work. Could anyone help me with it?
I've used code provided in API.txt, and context_reaction_debug.inc code (my module is attached (consists of 3 files)):
mymodule.module:
function mymodule_context_plugins() {
var_dump(__FUNCTION__);
$plugins = array();
$plugins['mymodule_context_reaction_bar'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'mymodule'),
'file' => 'mymodule_context_reaction_bar.inc',
'class' => 'mymodule_context_reaction_bar',
'parent' => 'context_reaction',
),
);
return $plugins;
}
function mymodule_context_registry() {
return array(
'reactions' => array(
'bar' => array(
'title' => t('Name of reaction'),
'plugin' => 'mymodule_context_reaction_bar',
),
),
);
}
mymodule_context_reaction_bar.inc:
// $Id: context_reaction_debug.inc,v 1.1.2.3 2010/08/04 23:43:04 yhahn Exp $
/**
* Output context debug information.
*/
var_dump(__FILE__);
class mymodule_context_reaction_bar extends context_reaction {
function options_form($context) {
return array('bar' => array('#type' => 'value', '#value' => TRUE));
}
function options_form_submit($values) {
return array('bar' => 1);
}
/**
* Output a list of active contexts.
*/
function execute() {
var_dump(__METHOD__);
$contexts = context_active_contexts();
foreach ($contexts as $context) {
if (!empty($context->reactions['debug'])) {
if (user_access('administer site configuration') && module_exists('context_ui')) {
$name = l($context->name, "admin/build/context/list/{$context->name}", array('query' => 'destination=' . $_GET['q']));
}
else {
$name = check_plain($context->name);
}
drupal_set_message(t("Active context: !name", array('!name' => $name)));
}
}
}
}
After saving condition/reaction pair and triggering the condition (site wide / path) the "string(24) "mymodule_context_plugins"" is displayed once, and then disappears.
Any ideas?
Comment | File | Size | Author |
---|---|---|---|
mymodule.zip | 1.3 KB | ger.lv |
Comments
Comment #1
RobLoachYou can create your own reaction, but the reaction itself is never actually executed. Seems to be on Drupal 7 as well.
Comment #2
iamjon CreditAttribution: iamjon commentedIt seems I have a similar problem http://drupal.org/node/1150770 Should I mark mine a dupe?
I'm using the almost the exact code in d.6 I've attached my reaction to a context but context_active_contexts() gets nothing.
It does get fired though.
Sorry if it's not a dupe.
Comment #3
iamjon CreditAttribution: iamjon commentedThis maybe relevant http://drupal.org/node/966880
But I change the weight in my custom module via the db and still nothing.
Comment #4
RobLoachDiscovered what was missing in #1057894: Context Module Integration. The execute() function actually is never called. It's the module's responsibility to check when the Context is being used....
Comment #5
ericras CreditAttribution: ericras commentedThanks Rob, I had this issue and using hook_context_page_reaction() as you suggest did the trick.
I think this is a Docs issue and hook_context_page_reaction() needs to be included in context.api.php and API.txt
Comment #6
febbraro CreditAttribution: febbraro commentedThanks, docs fixed.
http://drupalcode.org/project/context.git/commit/e364f65