You are here

mobile_tools_context.module in Mobile Tools 7.2

Same filename and directory in other branches
  1. 7.3 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()) {

    /**
     * We set the context
     */
    if (module_exists('context')) {
      $plugin = context_get_plugin('condition', 'mobile');
      if (!empty($plugin)) {
        $device = mobile_tools_get_active_device_group();

        // Init all active device groups
        foreach ($device as $key => $group) {
          $plugin
            ->execute($group['type']);
        }
      }
    }
  }
}

// CTools Integration

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

// Context Module Integration

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

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