You are here

class context_reaction_active_theme in Context Reaction: Theme 6.2

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

Expose themes as context reactions.

Hierarchy

Expanded class hierarchy of context_reaction_active_theme

3 string references to 'context_reaction_active_theme'
context_reaction_theme_context_plugins in ./context_reaction_theme.module
CTools plugin API hook for Context
context_reaction_theme_context_registry in ./context_reaction_theme.module
Registry hook for conditions & reactions.
context_reaction_theme_init in ./context_reaction_theme.module
Implementation of hook_init().

File

plugins/context_reaction_active_theme.inc, line 6

View source
class context_reaction_active_theme extends context_reaction {

  /**
   * Allow admins to choose the theme to be set.
   */
  function options_form($context) {
    $options = array();
    foreach (list_themes() as $name => $theme) {
      if ($theme->status) {
        $options[$name] = $name;
      }
    }
    $values = $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($values['theme']) ? $values['theme'] : '',
      ),
    );
    return $form;
  }

  /**
   * Set the active theme.
   */
  function execute() {
    foreach (context_active_contexts() as $context) {
      if (!empty($context->reactions[$this->plugin]['theme'])) {
        global $custom_theme;
        $custom_theme = $context->reactions[$this->plugin]['theme'];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
context_reaction_active_theme::execute function Set the active theme.
context_reaction_active_theme::options_form function Allow admins to choose the theme to be set.