class contextphp_condition_php in Context PHP 6
Same name and namespace in other branches
- 7 plugins/contextphp_condition_php.inc \contextphp_condition_php
PHP code as a Context condition.
Hierarchy
- class \contextphp_condition_php extends \context_condition
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 6
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' => $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'] . ' ?>';
$return = drupal_eval($code);
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. | ||
contextphp_condition_php:: |
function | |||
contextphp_condition_php:: |
function | |||
contextphp_condition_php:: |
function | |||
contextphp_condition_php:: |
function |