class contextphp_reaction_php in Context PHP 7
Same name and namespace in other branches
- 6 plugins/contextphp_reaction_php.inc \contextphp_reaction_php
 
PHP code as a Context reaction.
Hierarchy
- class \context_reaction
- class \contextphp_reaction_php
 
 
Expanded class hierarchy of contextphp_reaction_php
2 string references to 'contextphp_reaction_php'
- contextphp_context_plugins in ./
contextphp.module  - Implementation of hook_context_plugins().
 - contextphp_context_registry in ./
contextphp.module  - Implementation of hook_context_registry().
 
File
- plugins/
contextphp_reaction_php.inc, line 11  - contextphp_reaction_php.inc Adds php reaction to Context
 
View source
class contextphp_reaction_php extends context_reaction {
  /**
   * Editor form.
   */
  function editor_form($context) {
    $form['#type'] = 'value';
    $form['#value'] = TRUE;
    return $form;
  }
  /**
   * Submit handler for editor form.
   */
  function editor_form_submit($context, $values) {
    return array(
      $values,
    );
  }
  function options_form($context) {
    $defaults = $this
      ->fetch_from_context($context, 'options');
    return array(
      'phpcode' => array(
        '#type' => 'textarea',
        '#title' => t('PHP code'),
        '#description' => t('Enter PHP code that will react on the given condition. Do not use <?php ?>.'),
        '#default_value' => isset($defaults['phpcode']) ? $defaults['phpcode'] : '',
      ),
    );
  }
  function execute() {
    foreach (context_active_contexts() as $context) {
      $options = $this
        ->fetch_from_context($context, 'options');
      if (!empty($options['phpcode'])) {
        $code = '<?php ' . $options['phpcode'] . ' ?>';
        if (module_exists('php')) {
          php_eval($code);
        }
        else {
          drupal_set_message(t("Please enable 'PHP filter' to allow the 'Context PHP' module to evaluate your code."), 'warning', TRUE);
          return FALSE;
        }
      }
    }
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            contextphp_reaction_php:: | 
                  function | Editor form. | ||
| 
            contextphp_reaction_php:: | 
                  function | Submit handler for editor form. | ||
| 
            contextphp_reaction_php:: | 
                  function | |||
| 
            contextphp_reaction_php:: | 
                  function | 
            Overrides context_reaction:: | 
                  ||
| 
            context_reaction:: | 
                  property | |||
| 
            context_reaction:: | 
                  property | |||
| 
            context_reaction:: | 
                  property | |||
| 
            context_reaction:: | 
                  function | Retrieve options from the context provided. | 1 | |
| 
            context_reaction:: | 
                  function | Retrieve active contexts that have values for this reaction. | ||
| 
            context_reaction:: | 
                  function | Options form submit handler. | 3 | |
| 
            context_reaction:: | 
                  function | Settings form. Provide variable settings for your reaction. | 2 | |
| 
            context_reaction:: | 
                  function | Clone our references when we're being cloned. | ||
| 
            context_reaction:: | 
                  function | Constructor. Do not override. |