You are here

mobile_tools_context.module in Mobile Tools 7.3

Same filename and directory in other branches
  1. 7.2 mobile_tools_context/mobile_tools_context.module

Define mobile contexts. Works with the Context module as well as contexts with CTools

File

mobile_tools_context/mobile_tools_context.module
View source
<?php

/**
 * @file
 *
 * Define mobile contexts. Works with the Context module as well as contexts
 * with CTools
 */

/**
 * Implements hook_init().
 */
function mobile_tools_context_init() {
  if (!drupal_is_cli()) {
    if (module_exists('context')) {
      $plugin = context_get_plugin('condition', 'device_group');
      if (!empty($plugin)) {
        $device_group = mobile_tools_get_active_device_group();
        if (FALSE !== $device_group) {

          // Init the device group
          $plugin
            ->execute($device_group);
        }
      }
    }
  }
}

// CTools Integration
function mobile_tools_context_ctools_plugin_api($module, $api) {
  if ($module == "context" && $api == "context") {
    return array(
      "version" => 3,
    );
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function mobile_tools_context_ctools_plugin_directory($module, $plugin) {
  if ($plugin == 'access') {
    return 'plugins/' . $plugin;
  }
}

// Context Module Integration

/**
 * Implements of hook_context_plugins().
 */
function mobile_tools_context_context_plugins() {
  $plugins = array();
  $plugins['mobile_tools_context_condition_device_group'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'mobile_tools_context'),
      'file' => 'mobile_tools_context.condition_device_group.inc',
      'class' => 'mobile_tools_context_condition_device_group',
      'parent' => 'context_condition',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_context_registry().
 */
function mobile_tools_context_context_registry() {
  return array(
    'conditions' => array(
      'device_group' => array(
        'title' => t('Device Group'),
        'plugin' => 'mobile_tools_context_condition_device_group',
        'description' => t('Activate the context based on the active device group.'),
      ),
    ),
  );
}