You are here

class DynamicBackgroundReaction in Dynamic Background 7.2

Same name and namespace in other branches
  1. 6 modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc \DynamicBackgroundReaction
  2. 7 modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc \DynamicBackgroundReaction

@file Implements a new context reaction that can be used to set dynamic background images based on context.

Hierarchy

Expanded class hierarchy of DynamicBackgroundReaction

1 string reference to 'DynamicBackgroundReaction'
dynamic_background_context_context_plugins in modules/dynamic_background_context/dynamic_background_context.module
Implements hook_context_plugins().

File

modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc, line 8
Implements a new context reaction that can be used to set dynamic background images based on context.

View source
class DynamicBackgroundReaction extends context_reaction {
  function options_form($context) {
    $form = array();
    $form['dynamic_background'] = array(
      '#type' => 'fieldset',
      '#title' => t('Dynamic background'),
      '#description' => t('Select the image that you want for the current context.'),
      '#collapsed' => FALSE,
      '#collapsible' => TRUE,
      '#tree' => TRUE,
    );

    // Add the image selection part of the form.
    $form['dynamic_background'] += dynamic_background_image_selector_form('context', $context->name);
    return $form;
  }

  /**
   * Options form submit handler.
   */
  function options_form_submit($values) {

    // Check if any image have been selected.
    $fid = NULL;
    foreach ($values['dynamic_background'] as $key => $value) {
      if (isset($value['selected']) && $value['selected']) {
        $fid = $key;
        break;
      }
    }

    // Get dynamic background info.
    $info = $values['dynamic_background']['dynamic_background_info'];

    // Update the active background image.
    dynamic_background_set_active($fid, 'context', $info['data']);
    return $values;
  }

  /**
   * Find the selected image and return its id.
   */
  function execute() {
    $image = FALSE;
    foreach ($this
      ->get_contexts() as $context) {
      if (isset($context->reactions['dynamic_background'])) {
        $image = dynamic_background_active_image('context', $context->name);

        // If no image have been found try to select random image
        // (if configured).
        $image_behaviour = variable_get('dynamic_background_context_image_behaviour', array());
        if (!$image && (isset($image_behaviour['random']) && $image_behaviour['random'])) {
          $image = dynamic_background_random_image('context', $context->name);
        }
        break;
      }
    }
    return $image;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
context_reaction::$description property
context_reaction::$plugin property
context_reaction::$title property
context_reaction::fetch_from_context function Retrieve options from the context provided. 1
context_reaction::get_contexts function Retrieve active contexts that have values for this reaction.
context_reaction::settings_form function Settings form. Provide variable settings for your reaction. 2
context_reaction::__clone function Clone our references when we're being cloned.
context_reaction::__construct function Constructor. Do not override.
DynamicBackgroundReaction::execute function Find the selected image and return its id.
DynamicBackgroundReaction::options_form function Overrides context_reaction::options_form
DynamicBackgroundReaction::options_form_submit function Options form submit handler. Overrides context_reaction::options_form_submit