Newer
Older
The Great Git Migration
committed
<?php
/**
* @file
* Contains the php code argument default plugin.
*/
/**
* Default argument plugin to provide a PHP code block.
*/
class views_plugin_argument_default_php extends views_plugin_argument_default {
function option_definition() {
$options = parent::option_definition();
$options['code'] = array('default' => '');
The Great Git Migration
committed
return $options;
}
function options_form(&$form, &$form_state) {
$form['code'] = array(
The Great Git Migration
committed
'#type' => 'textarea',
'#title' => t('PHP contextual filter code'),
'#default_value' => $this->options['code'],
'#description' => t('Enter PHP code that returns a value to use for this filter. Do not use <?php ?>. You must return only a single value for just this filter.'),
The Great Git Migration
committed
);
// Only do this if using one simple standard form gadget
$this->check_access($form, 'code');
}
function convert_options(&$options) {
if (!isset($options['code']) && isset($this->argument->options['default_argument_php'])) {
$options['code'] = $this->argument->options['default_argument_php'];
}
The Great Git Migration
committed
}
/**
* Only let users with PHP block visibility permissions set/modify this
* default plugin.
*/
function access() {
return user_access('use PHP for settings');
The Great Git Migration
committed
}
function get_argument() {
The Great Git Migration
committed
// set up variables to make it easier to reference during the argument.
$view = &$this->view;
$argument = &$this->argument;
ob_start();
$result = eval($this->options['code']);
The Great Git Migration
committed
ob_end_clean();
return $result;
}
}