summaryrefslogtreecommitdiffstats
path: root/plugins/views_plugin_argument_default_php.inc
blob: 607b16e4b986df713baee8bc73415dbcd5c7eeb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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' => '');

    return $options;
  }

  function options_form(&$form, &$form_state) {
    $form['code'] = array(
      '#type' => 'textarea',
      '#title' => t('PHP contextual filter code'),
      '#default_value' => $this->options['code'],
      '#process' => array('ctools_dependent_process'),
      '#description' => t('Enter PHP code that returns a value to use for this filter. Do not use &lt;?php ?&gt;. You must return only a single value for just this filter.'),
    );

    // 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'];
    }
  }

  /**
   * Only let users with PHP block visibility permissions set/modify this
   * default plugin.
   */
  function access() {
    return user_access('use PHP for settings');
  }

  function get_argument() {
    // 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']);
    ob_end_clean();
    return $result;
  }
}