summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoung hahn2010-02-09 20:09:58 (GMT)
committer young hahn2010-02-09 20:09:58 (GMT)
commit2d0bdcb39a9a07ea71c00888f4cf7cc593ab3f43 (patch)
tree48a59f24a3dde9971e9613d4a85ed9ce8e5e906a
parent61a48b6a1b159d31f13369127372be660a7b0e8a (diff)
Adding API.txt and README.txt
-rw-r--r--API.txt91
-rw-r--r--README.txt23
2 files changed, 101 insertions, 13 deletions
diff --git a/API.txt b/API.txt
new file mode 100644
index 0000000..d92afd1
--- /dev/null
+++ b/API.txt
@@ -0,0 +1,91 @@
+$Id$
+
+Context 3.x API
+---------------
+The following is an overview of using the Context API.
+
+
+The context static cache
+------------------------
+Context provides a centralized set of API functions for setting and retrieving a
+static cache:
+
+ // Set a static cache value at [my_namspace][mykey]
+ context_set('my_namespace', 'mykey', $value);
+
+ // Retrieve a static cache value at [my_namespace][mykey]
+ context_get('my_namespace', 'mykey'); // $value
+
+ // Boolean for whether there is a value at [my_namespace][mykey]
+ context_isset('my_namespace', 'mykey'); // TRUE
+
+These are used internally by context but may also be used by other modules. Just
+do not use the namespace `context` unless you want to affect things that context
+is up to.
+
+
+Adding a condition or reaction plugin
+-------------------------------------
+Both context conditions and reactions utilize the CTools plugins API. In order
+to add a new condition or reaction for your module, follow these steps:
+
+1. Implement `hook_ctools_plugin_api()` in your module. This declares that your
+ module is API compatible with Context 3.
+
+ function mymodule_ctools_plugin_api($module, $api) {
+ if ($module == 'context' && $api == 'plugins') {
+ return array('version' => 3);
+ }
+ }
+
+2. Implement `hook_context_plugins()` to define your plugins, classes, and class
+ hierarchy.
+
+ function mymodule_context_plugins() {
+ $plugins = array();
+ $plugins['mymodule_context_condition_bar'] = array(
+ 'handler' => array(
+ 'path' => drupal_get_path('module', 'mymodule') .'/plugins',
+ 'file' => 'mymodule_context_condition_bar.inc',
+ 'class' => 'mymodule_context_condition_bar',
+ 'parent' => 'context_condition',
+ ),
+ );
+ return $plugins;
+ }
+
+3. Implement `hook_context_registry()` to define your conditions and/or
+ reactions and map them to plugins.
+
+ function mymodule_context_registry() {
+ return array(
+ 'conditions' => array(
+ 'bar' => array(
+ 'title' => t('Name of condition "bar"'),
+ 'plugin' => 'mymodule_context_condition_bar',
+ ),
+ ),
+ );
+ }
+
+4. Write your condition or reaction plugin class. It's best to look at one of
+ the included plugins as a starting point.
+
+5. Add in a Drupal integration point for your plugin. A node page condition
+ plugin, for example, may be invoked from `hook_nodeapi()`.
+
+
+Replacing or extending existing plugins
+---------------------------------------
+You can replace a condition or reaction plugin with your own plugin class using
+`hook_context_registry_alter()`:
+
+ function mymodule_context_registry_alter(&$registry) {
+ if (!empty($registry['conditions']['node'])) {
+ $registry['conditions']['node']['plugin'] = 'mymodule_context_condition_customnode';
+ }
+ }
+
+This entry would swap out the default node condition plugin for a custom one
+provided by `mymodule`. Note that any replacement plugins must have an entry in
+`hook_context_plugins()`.
diff --git a/README.txt b/README.txt
index f2de9dd..36d1516 100644
--- a/README.txt
+++ b/README.txt
@@ -1,6 +1,16 @@
$Id$
Context 3.x for Drupal 6.x
+--------------------------
+Context allows you to manage contextual conditions and reactions for
+different portions of your site. You can think of each context as
+representing a "section" of your site. For each context, you can choose
+the conditions that trigger this context to be active and choose different
+aspects of Drupal that should react to this active context.
+
+Think of conditions as a set of rules that are checked during page load
+to see what context is active. Any reactions that are associated with
+active contexts are then fired.
Installation
@@ -13,19 +23,6 @@ You will probably also want to install Context UI which provides a way for
you to edit contexts through the Drupal admin interface.
-Basic usage
------------
-Context allows you to manage contextual conditions and reactions for
-different portions of your site. You can think of each context as
-representing a "section" of your site. For each context, you can choose
-the conditions that trigger this context to be active and choose different
-aspects of Drupal that should react to this active context.
-
-Think of conditions as a set of rules that are checked during page load
-to see what context is active. Any reactions that are associated with
-active contexts are then fired.
-
-
Example
-------
You want to create a "pressroom" section of your site. You have a press