1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_argument_default_php.
|
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
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
$options['code'] = array('default' => '');
|
21
|
|
22
|
return $options;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function options_form(&$form, &$form_state) {
|
29
|
parent::options_form($form, $form_state);
|
30
|
$form['code'] = array(
|
31
|
'#type' => 'textarea',
|
32
|
'#title' => t('PHP contextual filter code'),
|
33
|
'#default_value' => $this->options['code'],
|
34
|
'#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"".'),
|
35
|
);
|
36
|
|
37
|
// Only do this if using one simple standard form gadget.
|
38
|
$this->check_access($form, 'code');
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* {@inheritdoc}
|
43
|
*/
|
44
|
public function convert_options(&$options) {
|
45
|
if (!isset($options['code']) && isset($this->argument->options['default_argument_php'])) {
|
46
|
$options['code'] = $this->argument->options['default_argument_php'];
|
47
|
}
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Only let users with PHP block visibility permissions set/modify this
|
52
|
* default plugin.
|
53
|
*/
|
54
|
public function access() {
|
55
|
return user_access('use PHP for settings');
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* {@inheritdoc}
|
60
|
*/
|
61
|
public function get_argument() {
|
62
|
// set up variables to make it easier to reference during the argument.
|
63
|
$view = &$this->view;
|
64
|
$argument = &$this->argument;
|
65
|
ob_start();
|
66
|
$result = eval($this->options['code']);
|
67
|
ob_end_clean();
|
68
|
return $result;
|
69
|
}
|
70
|
|
71
|
}
|