You are here

dynamic_background_context.module in Dynamic Background 6

File

modules/dynamic_background_context/dynamic_background_context.module
View source
<?php

/**
 * Implementation of hook_perm().
 */
function dynamic_background_context_perm() {
  return array(
    'configure context dynamic background',
  );
}

/**
 * Implementation of hook_menu(). Hooks into the dynamic background modules menu
 * structure and adds the "context" menu tab to the administration interface.
 *
 * @return array menu items
 */
function dynamic_background_context_menu() {
  $items = array();
  $items['admin/build/backgrounds/context'] = array(
    'title' => 'Context',
    'description' => t('Configure dynamic background context'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dynamic_background_context_admin_form',
    ),
    'access arguments' => array(
      'configure context dynamic background',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => -10,
  );
  return $items;
}

/**
 * Build the administration interface for dynamic background context and enables
 * administrators to set image style and css targets.
 *
 * @return array $form
 */
function dynamic_background_context_admin_form() {
  $form = array(
    '#tree' => TRUE,
  );

  // Add image style to the form.
  $form += dynamic_background_image_presents_form('dynamic_background_context_imagecache');

  // Add css behaviour form to the form.
  $form += dynamic_background_css_behaviour_form('dynamic_background_context_css');
  return system_settings_form($form);
}

/**
 * Implements hook_context_plugins().
 */
function dynamic_background_context_context_plugins() {
  return array(
    'dynamic_background_context_reaction' => array(
      'handler' => array(
        'path' => drupal_get_path('module', 'dynamic_background_context') . '/plugins',
        'file' => 'dynamic_background_context_reaction.inc',
        'class' => 'DynamicBackgroundReaction',
        'parent' => 'context_reaction',
      ),
    ),
  );
}

/**
 * Implementation of hook_context_registry()
 */
function dynamic_background_context_context_registry() {
  return array(
    'reactions' => array(
      'dynamic_background' => array(
        // Space is not allowed in the name.
        'title' => t('Dynamic background'),
        'description' => t('Enable different backgrounds base on a given context.'),
        'plugin' => 'dynamic_background_context_reaction',
      ),
    ),
  );
}

/**
 * Implements hook_dynamic_background_css().
 */
function dynamic_background_context_dynamic_background_css($vars) {

  // Find the selected image id.
  $image_id = NULL;
  $plugin = context_get_plugin('reaction', 'dynamic_background');
  if ($plugin) {
    $image_id = $plugin
      ->execute();
  }

  // Load imagecache settings.
  $imagecache = variable_get('dynamic_background_context_imagecache', FALSE);

  // Generate the css based in the image id.
  if (!is_null($image_id)) {
    $backgrounds = variable_get('dynamic_background_images', array());
    if (isset($backgrounds[$image_id]['picture'])) {

      // Load image style settings.
      $image_style = variable_get('dynamic_background_context_image_style', FALSE);
      return array(
        'image' => $backgrounds[$image_id]['default'],
        'configuration' => variable_get('dynamic_background_context_css', array()),
        'imagecache' => $imagecache ? $imagecache['present'] : FALSE,
        'weight' => 225,
      );
    }
  }
}

Functions

Namesort descending Description
dynamic_background_context_admin_form Build the administration interface for dynamic background context and enables administrators to set image style and css targets.
dynamic_background_context_context_plugins Implements hook_context_plugins().
dynamic_background_context_context_registry Implementation of hook_context_registry()
dynamic_background_context_dynamic_background_css Implements hook_dynamic_background_css().
dynamic_background_context_menu Implementation of hook_menu(). Hooks into the dynamic background modules menu structure and adds the "context" menu tab to the administration interface.
dynamic_background_context_perm Implementation of hook_perm().