class contextphp_condition_php in Context PHP 7
Same name and namespace in other branches
- 6 plugins/contextphp_condition_php.inc \contextphp_condition_php
PHP code as a Context condition.
Hierarchy
- class \context_condition
- class \contextphp_condition_php
Expanded class hierarchy of contextphp_condition_php
2 string references to 'contextphp_condition_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_condition_php.inc, line 11 - contextphp_condition_php.inc Adds php argument condition to Context
View source
class contextphp_condition_php extends context_condition {
function condition_values() {
return array(
1 => t('True'),
);
}
/**
* Our value is always TRUE. The PHP code in the options form descides if it
* validates or not on runtime.
*/
function condition_form($context) {
$form['#type'] = 'value';
$form['#value'] = TRUE;
return $form;
}
function condition_form_submit($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 returns TRUE if the condition shall be met. Do not use <?php ?>.'),
'#default_value' => isset($defaults['phpcode']) ? $defaults['phpcode'] : '',
),
);
}
function execute() {
foreach (context_enabled_contexts() as $context) {
$options = $this
->fetch_from_context($context, 'options');
if (!empty($options['phpcode'])) {
$code = '<?php ' . $options['phpcode'] . ' ?>';
if (module_exists('php')) {
$return = 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;
}
if ($return == TRUE) {
$this
->condition_met($context, $return);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
contextphp_condition_php:: |
function |
Our value is always TRUE. The PHP code in the options form descides if it
validates or not on runtime. Overrides context_condition:: |
||
contextphp_condition_php:: |
function |
Condition form submit handler. Overrides context_condition:: |
||
contextphp_condition_php:: |
function |
Condition values. Overrides context_condition:: |
||
contextphp_condition_php:: |
function | |||
contextphp_condition_php:: |
function |
Options form. Provide additional options for your condition. Overrides context_condition:: |
||
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
function | Marks a context as having met this particular condition. | ||
context_condition:: |
function | Check whether this condition is used by any contexts. Can be used to prevent expensive condition checks from being triggered when no contexts use this condition. | ||
context_condition:: |
function | Context editor form for conditions. | 2 | |
context_condition:: |
function | Context editor form submit handler. | ||
context_condition:: |
function | Retrieve options from the context provided. | ||
context_condition:: |
function | Retrieve all contexts with the condition value provided. | 2 | |
context_condition:: |
function | Options form submit handler. | ||
context_condition:: |
function | Settings form. Provide variable settings for your condition. | ||
context_condition:: |
function | Clone our references when we're being cloned. | ||
context_condition:: |
function | Constructor. Do not override. |