context_reaction.inc

Go to the documentation of this file.
00001 <?php
00002 
00003 /**
00004  * Base class for a context reaction.
00005  */
00006 class context_reaction {
00007   var $plugin;
00008   var $title;
00009   var $description;
00010 
00011   /**
00012    * Clone our references when we're being cloned.
00013    *
00014    * PHP 5.3 performs 'shallow' clones when clone()'ing objects, meaning that
00015    * any objects or arrays referenced by this object will not be copied, the
00016    * cloned object will just reference our objects/arrays instead. By iterating
00017    * over our properties and serializing and unserializing them, we force PHP to
00018    * copy them.
00019    */
00020   function __clone() {
00021     foreach ($this as $key => $val) {
00022       if (is_object($val) || (is_array($val))) {
00023         $this->{$key} = unserialize(serialize($val));
00024       }
00025     }
00026   }
00027 
00028   /**
00029    * Constructor. Do not override.
00030    */
00031   function __construct($plugin, $info) {
00032     $this->plugin = $plugin;
00033     $this->title = isset($info['title']) ? $info['title'] : $plugin;
00034     $this->description = isset($info['description']) ? $info['description'] : '';
00035   }
00036 
00037   function options_form($context) {
00038     return array();
00039   }
00040 
00041   /**
00042    * Options form submit handler.
00043    */
00044   function options_form_submit($values) {
00045     return $values;
00046   }
00047 
00048   /**
00049    * Settings form. Provide variable settings for your reaction.
00050    */
00051   function settings_form() {
00052     return array();
00053   }
00054 
00055   /**
00056    * Public method that is called from hooks or other integration points with
00057    * Drupal. Note that it is not implemented in the base class, allowing
00058    * extending classes to change the function signature if necessary.
00059    *
00060    * function execute($value) {
00061    *   foreach ($this->get_contexts($value) as $context) {
00062    *     $this->condition_met($context, $value);
00063    *   }
00064    * }
00065    */
00066 
00067   /**
00068    * Retrieve active contexts that have values for this reaction.
00069    */
00070   function get_contexts() {
00071     $contexts = array();
00072     foreach (context_active_contexts() as $context) {
00073       if ($this->fetch_from_context($context)) {
00074         $contexts[$context->name] = $context;
00075       }
00076     }
00077     return $contexts;
00078   }
00079 
00080   /**
00081    * Retrieve options from the context provided.
00082    */
00083   function fetch_from_context($context) {
00084     return isset($context->reactions[$this->plugin]) ? $context->reactions[$this->plugin] : array();
00085   }
00086 }

Generated on Wed May 22 02:23:48 2013 for Context by  doxygen 1.4.7