You are here

dynamic_background_context.module in Dynamic Background 7.2

File

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

/**
 * 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_settings_form() {
  $form = array();

  // Add image style to the form.
  $form += dynamic_background_image_style_form('dynamic_background_context_image_style');

  // Add image behavior form.
  $form += dynamic_background_image_behaviour_form('dynamic_background_context_image_behaviour');
  return $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',
      ),
    ),
  );
}

/**
 * Implements 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 = FALSE;
  $plugin = context_get_plugin('reaction', 'dynamic_background');
  if ($plugin) {
    $image = $plugin
      ->execute();
  }

  // If image is defined for the current context, return configuration options.
  if ($image) {

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

/**
 * Implements hook_dynamic_background_info().
 */
function dynamic_background_context_dynamic_background_info() {
  return array(
    'type' => 'context',
    'menu' => array(
      'title' => t('Context'),
      'description' => t('Configure context extension'),
    ),
    'upload' => FALSE,
  );
}

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