Context Callback

Categories

Component ID

2130755

Component name

Context Callback

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

1153

Component created

Component changed

Component body

A small module to allow your own callbacks for activating and reacting to contexts (context module). No need to write a context-plugin; this module provides a simple hook to register the callbacks and/or reactions that will be picked up by context.

Installation

Context Callback can be installed like any other Drupal module: place it in the modules directory for your site and enable it on the `admin/modules` page.

Usage

Implement the `hook_context_callback_info` hook in your own module. With this hook, you let the Context Callback know of your callback functions.
Each callback will be called upon page-view to see whether or not it should trigger the context.

Example code

  // mymodule.module
  /**
   * Implements hook_context_callback_info().
   */
  function mymodule_context_callback_info() {
    return array(
      'conditions' => array(
        'mymodule_condition_callback_id' => array(
          'label' => 'MyModule Callback Example',
          'callback' => 'mymodule_condition_callback_example',
          // Optional.
          'callback arguments' => array(
            'argument 1',
            'argument 2',
          ),
        ),
      ),
      'reactions' => array(
        'mymodule_reaction_callback_id' => array(
          'label' => 'MyModule Callback Example',
          'callback' => 'mymodule_reaction_callback_example',
          // Optional.
          'callback arguments' => array(
            'argument 1',
            'argument 2',
          ),
        ),
      ),
    );
  }

  /**
   * Callback example function.
   */
  function mymodule_condition_callback_example($argument1, $argument2) {
    if (/* Do some checks to see if the context should trigger */) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Callback example function.
   */
  function mymodule_reaction_callback_example($argument1, $argument2) {
    /* Do something awesome */
  }