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