views_plugin_argument_default_php.inc

  1. 3.x plugins/views_plugin_argument_default_php.inc
  2. 2.x plugins/views_plugin_argument_default_php.inc

Contains the php code argument default plugin.

File

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