1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains the php code argument default plugin.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Default argument plugin to provide a PHP code block.
|
10
|
*
|
11
|
* @ingroup views_argument_default_plugins
|
12
|
*/
|
13
|
class views_plugin_argument_default_php extends views_plugin_argument_default {
|
14
|
function option_definition() {
|
15
|
$options = parent::option_definition();
|
16
|
$options['code'] = array('default' => '');
|
17
|
|
18
|
return $options;
|
19
|
}
|
20
|
|
21
|
function options_form(&$form, &$form_state) {
|
22
|
parent::options_form($form, $form_state);
|
23
|
$form['code'] = array(
|
24
|
'#type' => 'textarea',
|
25
|
'#title' => t('PHP contextual filter code'),
|
26
|
'#default_value' => $this->options['code'],
|
27
|
'#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. Some variables are available: the view object will be "$view". The argument handler will be "$argument", for example you may change the title used for substitutions for this argument by setting "argument->validated_title"".'),
|
28
|
);
|
29
|
|
30
|
// Only do this if using one simple standard form gadget
|
31
|
$this->check_access($form, 'code');
|
32
|
}
|
33
|
|
34
|
function convert_options(&$options) {
|
35
|
if (!isset($options['code']) && isset($this->argument->options['default_argument_php'])) {
|
36
|
$options['code'] = $this->argument->options['default_argument_php'];
|
37
|
}
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Only let users with PHP block visibility permissions set/modify this
|
42
|
* default plugin.
|
43
|
*/
|
44
|
function access() {
|
45
|
return user_access('use PHP for settings');
|
46
|
}
|
47
|
|
48
|
function get_argument() {
|
49
|
// set up variables to make it easier to reference during the argument.
|
50
|
$view = &$this->view;
|
51
|
$argument = &$this->argument;
|
52
|
ob_start();
|
53
|
$result = eval($this->options['code']);
|
54
|
ob_end_clean();
|
55
|
return $result;
|
56
|
}
|
57
|
}
|