You are here

class DynamicBackgroundReaction in Dynamic Background 7

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

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 3

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($this
      ->find_selected_image($context));
    return $form;
  }

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

    // Remove the extra level, that the field set above creates.
    return array_pop($values);
  }

  /**
   * Find the selected image and return its id.
   */
  function execute() {
    $image_id = NULL;
    foreach ($this
      ->get_contexts() as $context) {
      $image_id = $this
        ->find_selected_image($context);
    }
    return $image_id;
  }
  function find_selected_image($context) {

    // Find the currently selected image
    if (isset($context->reactions['dynamic_background'])) {
      foreach ($context->reactions['dynamic_background'] as $id => $value) {
        if (isset($value['selected']) && $value['selected']) {
          return $id;
        }
      }
    }
    return NULL;
  }

}

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::find_selected_image function
DynamicBackgroundReaction::options_form function Overrides context_reaction::options_form
DynamicBackgroundReaction::options_form_submit function Options form submit handler. Overrides context_reaction::options_form_submit