You are here

class context_reaction_active_theme in Context Reaction: Theme 7

Same name and namespace in other branches
  1. 6.2 plugins/context_reaction_active_theme.inc \context_reaction_active_theme

Expose themes as context reactions.

Hierarchy

Expanded class hierarchy of context_reaction_active_theme

2 string references to 'context_reaction_active_theme'
context_reaction_theme_context_plugins in ./context_reaction_theme.module
Implements hook_context_plugins().
context_reaction_theme_context_registry in ./context_reaction_theme.module
Implements hook_context_registry().

File

plugins/context_reaction_theme.inc, line 11
Context plugin file to provide changing the active theme as a context reaction.

View source
class context_reaction_active_theme extends context_reaction {

  /**
   * Grab the available themes and provide them as a reaction for context.
   *
   * @param $context
   *   The context as passed from context module.
   *
   * @return array
   *   The FAPI array as read by context module.
   */
  function options_form($context) {
    $options = array();
    $themes = list_themes();
    foreach ($themes as $name => $theme) {

      // only allow active themes
      if ($theme->status == 1) {
        $options[$name] = $name;
      }
    }
    $settings = $this
      ->fetch_from_context($context);
    $form = array(
      '#tree' => TRUE,
      '#title' => t('Theme'),
      'theme' => array(
        '#title' => t('Active theme'),
        '#description' => t('Choose a theme to activate when this context is active.'),
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => isset($settings['theme']) ? $settings['theme'] : variable_get('theme_default', ''),
      ),
    );
    return $form;
  }

  /**
   * Return the active theme based on the context
   *
   * @return string | null
   *   String of the theme name, or NULL if not to be altered.
   */
  function execute() {
    $theme = NULL;
    foreach ($this
      ->get_contexts() as $context) {
      if (isset($context->reactions['active_theme']['theme'])) {
        $theme = $context->reactions['active_theme']['theme'];
      }
    }
    return $theme;
  }

}

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::options_form_submit function Options form submit handler. 3
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.
context_reaction_active_theme::execute function Return the active theme based on the context
context_reaction_active_theme::options_form function Grab the available themes and provide them as a reaction for context. Overrides context_reaction::options_form