context.api.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /**
00004  * @file
00005  * Hooks provided by Context.
00006  */
00007 
00008 /**
00009  * CTools plugin API hook for Context. Note that a proper entry in
00010  * hook_ctools_plugin_api() must exist for this hook to be called.
00011  */
00012 function hook_context_plugins() {
00013   $plugins = array();
00014   $plugins['foo_context_condition_bar'] = array(
00015     'handler' => array(
00016       'path' => drupal_get_path('module', 'foo') .'/plugins',
00017       'file' => 'foo_context_condition_bar.inc',
00018       'class' => 'foo_context_condition_bar',
00019       'parent' => 'context_condition',
00020     ),
00021   );
00022   $plugins['foo_context_reaction_baz'] = array(
00023     'handler' => array(
00024       'path' => drupal_get_path('module', 'foo') .'/plugins',
00025       'file' => 'foo_context_reaction_baz.inc',
00026       'class' => 'foo_context_reaction_baz',
00027       'parent' => 'context_reaction',
00028     ),
00029   );
00030   return $plugins;
00031 }
00032 
00033 /**
00034  * Registry hook for conditions & reactions.
00035  *
00036  * Each entry associates a condition or reaction with the CTools plugin to be
00037  * used as its plugin class.
00038  */
00039 function hook_context_registry() {
00040   return array(
00041     'conditions' => array(
00042       'bar' => array(
00043         'title' => t('Name of condition "bar"'),
00044         'plugin' => 'foo_context_condition_bar',
00045       ),
00046     ),
00047     'reactions' => array(
00048       'baz' => array(
00049         'title' => t('Name of reaction "baz"'),
00050         'plugin' => 'foo_context_reaction_baz',
00051       ),
00052     ),
00053   );
00054 }
00055 
00056 /**
00057  * Execute Context page conditions
00058  *
00059  * Allows modules to hook into Context's hook_page_build to execute their
00060  * conditions at an appropriate time before the firing of reactions.
00061  */
00062 function hook_context_page_condition() {
00063   if ($plugin = context_get_plugin('condition', 'bar')) {
00064     $plugin->execute();
00065   }
00066 }
00067 
00068 /**
00069  * Execute Context page reactions
00070  *
00071  * Allows modules to hook into Context's hook_page_build to execute their
00072  * reactions at an appropriate time after the firing of conditions.
00073  */
00074 function hook_context_page_reaction() {
00075   if ($plugin = context_get_plugin('reaction', 'baz')) {
00076     $plugin->execute();
00077   }
00078 }
00079 
00080 /**
00081  * Alter the registry.
00082  *
00083  * Allows modules to alter the registry. Default plugins can be replaced by
00084  * custom ones declared in hook_context_plugins().
00085  *
00086  * @param $registry
00087  *   The registry, passed by reference.
00088  */
00089 function hook_context_registry_alter(&$registry) {
00090   if (isset($registry['reactions']['baz'])) {
00091     $registry['reactions']['baz']['plugin'] = 'custom_context_reaction_baz';
00092   }
00093 }
00094 
00095 /**
00096  * Alter/add a condition to a node-related event.
00097  *
00098  * Allows modules to add one or more context condition plugin executions to a
00099  * node view, form, etc.
00100  *
00101  * @param $node
00102  *   The node object.
00103  * @param $op
00104  *   The node-related operation: 'node', 'form', 'comment'.
00105  */
00106 function hook_context_node_condition_alter(&$node, $op) {
00107   if ($plugin = context_get_plugin('condition', 'bar')) {
00108     $plugin->execute($node, $op);
00109   }
00110 }
00111 
00112 /**
00113  * Alter a context directly after it has been loaded. Allows modules to alter
00114  * a context object's reactions. While you may alter conditions, this will
00115  * generally have no effect as conditions are cached for performance and
00116  * contexts are loaded after conditions are checked, not before.
00117  *
00118  * @param &$context
00119  *   The context object by reference.
00120  */
00121 function hook_context_load_alter(&$context) {
00122   if ($context->name === 'foo' && isset($context->reactions['block'])) {
00123     $context->reactions['block']['blocks']['locale-0'] = array(
00124       'module' => 'locale',
00125       'delta' => '0',
00126       'region' => 'header',
00127       'weight' => '2',
00128     );
00129   }
00130 }

Generated on Tue May 21 02:23:48 2013 for Context by  doxygen 1.4.7