You are here

contextphp.module in Context PHP 7

Same filename and directory in other branches
  1. 6 contextphp.module

File

contextphp.module
View source
<?php

/**
 * Implementation of hook_context_plugins().
 */
function contextphp_context_plugins() {
  $module_path = drupal_get_path('module', 'contextphp');
  $plugins = array();
  $plugins['contextphp_condition_php'] = array(
    'handler' => array(
      'path' => $module_path . '/plugins',
      'file' => 'contextphp_condition_php.inc',
      'class' => 'contextphp_condition_php',
      'parent' => 'context_condition',
    ),
  );
  $plugins['contextphp_reaction_php'] = array(
    'handler' => array(
      'path' => $module_path . '/plugins',
      'file' => 'contextphp_reaction_php.inc',
      'class' => 'contextphp_reaction_php',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}

/**
 * Implementation of hook_context_registry().
 */
function contextphp_context_registry() {
  return array(
    'conditions' => array(
      'php' => array(
        'title' => t('PHP code'),
        'description' => t('Set this context when PHP code returns TRUE.'),
        'plugin' => 'contextphp_condition_php',
      ),
    ),
    'reactions' => array(
      'php' => array(
        'title' => t('PHP code'),
        'description' => t('React with the PHP code.'),
        'plugin' => 'contextphp_reaction_php',
      ),
    ),
  );
}

/**
 * Implementation of hook_init().
 */
function contextphp_init() {
  $map = context_condition_map();
  if (!empty($map['php']) && ($plugin = context_get_plugin('condition', 'php'))) {
    $plugin
      ->execute();
  }
  $map = context_reactions();
  if (!empty($map['php']) && ($plugin = context_get_plugin('reaction', 'php'))) {
    $plugin
      ->execute();
  }
}

Functions

Namesort descending Description
contextphp_context_plugins Implementation of hook_context_plugins().
contextphp_context_registry Implementation of hook_context_registry().
contextphp_init Implementation of hook_init().