views_handler_argument_null.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_argument_null.
  5. */
  6. /**
  7. * Argument handler that ignores the argument.
  8. *
  9. * @ingroup views_argument_handlers
  10. */
  11. class views_handler_argument_null extends views_handler_argument {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function option_definition() {
  16. $options = parent::option_definition();
  17. $options['must_not_be'] = array('default' => FALSE, 'bool' => TRUE);
  18. return $options;
  19. }
  20. /**
  21. * Override options_form() so that only the relevant options
  22. * are displayed to the user.
  23. */
  24. public function options_form(&$form, &$form_state) {
  25. parent::options_form($form, $form_state);
  26. $form['must_not_be'] = array(
  27. '#type' => 'checkbox',
  28. '#title' => t('Fail basic validation if any argument is given'),
  29. '#default_value' => !empty($this->options['must_not_be']),
  30. '#description' => t('By checking this field, you can use this to make sure views with more arguments than necessary fail validation.'),
  31. '#fieldset' => 'more',
  32. );
  33. unset($form['exception']);
  34. }
  35. /**
  36. * Override default_actions() to remove actions that don't
  37. * make sense for a null argument.
  38. */
  39. public function default_actions($which = NULL) {
  40. if ($which) {
  41. if (in_array($which, array('ignore', 'not found', 'empty', 'default', 'access denied'))) {
  42. return parent::default_actions($which);
  43. }
  44. return;
  45. }
  46. $actions = parent::default_actions();
  47. unset($actions['summary asc']);
  48. unset($actions['summary desc']);
  49. return $actions;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function validate_argument_basic($arg) {
  55. if (!empty($this->options['must_not_be'])) {
  56. return !isset($arg);
  57. }
  58. return parent::validate_argument_basic($arg);
  59. }
  60. /**
  61. * Override the behavior of query() to prevent the query
  62. * from being changed in any way.
  63. */
  64. public function query($group_by = FALSE) {
  65. }
  66. }