You are here

dynamic_background_context.module in Dynamic Background 7

File

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

/**
 * Implementation of hook_permission().
 */
function dynamic_background_context_permission() {
  return array(
    'configure context dynamic background' => array(
      'title' => t('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/config/user-interface/backgrounds/context'] = array(
    'title' => 'Context',
    'description' => t('Configure context dynamic background'),
    '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_style_form('dynamic_background_context_image_style');

  // 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();
  }

  // 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]['picture'],
        'configuration' => variable_get('dynamic_background_context_css', array()),
        'image_style' => $image_style ? $image_style['style'] : FALSE,
      );
    }
  }
}

/**
 * Implements hook_dynamic_background_weight for the main module.
 */
function dynamic_background_context_dynamic_background_weight() {
  return array(
    'weight' => -50,
  );
}

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_dynamic_background_weight Implements hook_dynamic_background_weight for the main module.
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_permission Implementation of hook_permission().