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. class views_plugin_argument_default_php extends views_plugin_argument_default {
  10. var $option_name = 'default_argument_php';
  11. function argument_form(&$form, &$form_state) {
  12. $form[$this->option_name] = array(
  13. '#type' => 'textarea',
  14. '#title' => t('PHP argument code'),
  15. '#default_value' => $this->get_argument(TRUE), // the true forces it raw.
  16. '#process' => array('views_process_dependency'),
  17. '#description' => t('Enter PHP code that returns a value to use for this argument. Do not use &lt;?php ?&gt;. You must return only a single value for just this argument.'),
  18. '#dependency' => array(
  19. 'radio:options[default_action]' => array('default'),
  20. 'radio:options[default_argument_type]' => array($this->id)
  21. ),
  22. '#dependency_count' => 2,
  23. );
  24. $this->check_access($form);
  25. }
  26. /**
  27. * Only let users with PHP block visibility permissions set/modify this
  28. * default plugin.
  29. */
  30. function access() {
  31. return user_access('use PHP for block visibility');
  32. }
  33. function get_argument($raw = FALSE) {
  34. if ($raw) {
  35. return parent::get_argument();
  36. }
  37. // set up variables to make it easier to reference during the argument.
  38. $view = &$this->view;
  39. $argument = &$this->argument;
  40. ob_start();
  41. $result = eval($this->argument->options[$this->option_name]);
  42. ob_end_clean();
  43. return $result;
  44. }
  45. }