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