views_handler_argument_null.inc

  1. 3.x handlers/views_handler_argument_null.inc
  2. 2.x handlers/views_handler_argument_null.inc

File

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