diff --git a/context/condition/masquerade_is_masquerading.inc b/context/condition/masquerade_is_masquerading.inc new file mode 100644 index 0000000..f1eea73 --- /dev/null +++ b/context/condition/masquerade_is_masquerading.inc @@ -0,0 +1,26 @@ + t('Evaluate this context when the current user is posing as someone else.')); + } + + /** + * hook_context_reaction() is required of your module and will have to call $plugin->execute() + * or this plugin won't do anything. + */ + function execute() { + if (isset($_SESSION['masquerading']) && is_numeric($_SESSION['masquerading'])) { + foreach ($this->get_contexts() as $context) { + $this->condition_met($context, 'is_masquerading'); + } + } + } +} diff --git a/masquerade.module b/masquerade.module index 9e990c8..775d5d6 100644 --- a/masquerade.module +++ b/masquerade.module @@ -840,3 +840,45 @@ function masquerade_switch_back() { $user = user_load($uid); watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array('%user' => $user->name, '%masq_as' => $oldname), WATCHDOG_INFO); } + +/** + * Implements hook_context_plugins(). + * Adds a masquerading condition to the context module + */ +function masquerade_context_plugins() { + $plugins = array(); + $plugins['masquerade_is_masquerading'] = array( + 'handler' => array( + 'path' => drupal_get_path('module', 'masquerade') .'/context/condition', + 'file' => 'masquerade_is_masquerading.inc', + 'class' => 'masquerade_is_masquerading_context_condition', + 'parent' => 'context_condition', + ), + ); + return $plugins; +} + +/** + * Implements hook_context_registry(). + * Tells the Context module to look for our custom plugins. + */ +function masquerade_context_registry() { + return array( + 'conditions' => array( + 'masquerade_is_masquerading' => array( + 'title' => t('User is Masquerading'), + 'description' => t('Sets this context when the current user is posing as someone else.'), + 'plugin' => 'masquerade_is_masquerading', + ), + ), + ); +} + +/** + * Triggers our custom context reactions. + */ +function masquerade_context_page_reaction() { + if ($plugin = context_get_plugin('condition', 'masquerade_is_masquerading')) { + $plugin->execute(); + } +}