6e797b49b1beb0114e0390123c2c5eb86d742121
[yaffs-website] / web / core / modules / views / src / Plugin / views / argument_validator / ArgumentValidatorPluginBase.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\argument_validator;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
7 use Drupal\views\Plugin\views\PluginBase;
8
9 /**
10  * @defgroup views_argument_validate_plugins Views argument validate plugins
11  * @{
12  * Plugins for validating views contextual filters.
13  *
14  * Views argument validator plugins validate arguments (contextual filters) on
15  * views. They can ensure arguments are valid, and even do transformations on
16  * the arguments. They can also provide replacement patterns for the view title.
17  * For example, the 'content' validator verifies verifies that the argument
18  * value corresponds to a node, loads that node, and provides the node title
19  * as a replacement pattern for the view title.
20  *
21  * Argument validator plugins extend
22  * \Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase.
23  * They must be annotated with
24  * \Drupal\views\Annotation\ViewsArgumentValidator annotation, and they
25  * must be in namespace directory Plugin\views\argument_validator.
26  *
27  * @ingroup views_plugins
28  * @see plugin_api
29  */
30
31 /**
32  * Base argument validator plugin to provide basic functionality.
33  */
34 abstract class ArgumentValidatorPluginBase extends PluginBase {
35
36   /**
37    * The argument handler instance associated with this plugin.
38    *
39    * @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase
40    */
41   protected $argument;
42
43   /**
44    * Sets the parent argument this plugin is associated with.
45    *
46    * @param \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument
47    *   The parent argument to set.
48    */
49   public function setArgument(ArgumentPluginBase $argument) {
50     $this->argument = $argument;
51   }
52
53   /**
54    * Retrieves the options when this is a new access control plugin.
55    */
56   protected function defineOptions() {
57     return [];
58   }
59
60   /**
61    * Provides the default form for setting options.
62    */
63   public function buildOptionsForm(&$form, FormStateInterface $form_state) {}
64
65   /**
66    * Provides the default form for validating options.
67    */
68   public function validateOptionsForm(&$form, FormStateInterface $form_state) {}
69
70   /**
71    * Provides the default form for submitting options.
72    */
73   public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {}
74
75   /**
76    * Determines if the administrator has the privileges to use this plugin.
77    */
78   public function access() {
79     return TRUE;
80   }
81
82   /**
83    * Blocks user input when the form is shown but we donĀ“t have access.
84    *
85    * This is only called by child objects if specified in the buildOptionsForm(),
86    * so it will not always be used.
87    */
88   protected function checkAccess(&$form, $option_name) {
89     if (!$this->access()) {
90       $form[$option_name]['#disabled'] = TRUE;
91       $form[$option_name]['#value'] = $form[$this->option_name]['#default_value'];
92       $form[$option_name]['#description'] .= ' <strong>' . $this->t('Note: you do not have permission to modify this. If you change the default filter type, this setting will be lost and you will NOT be able to get it back.') . '</strong>';
93     }
94   }
95
96   /**
97    * Performs validation for a given argument.
98    */
99   public function validateArgument($arg) {
100     return TRUE;
101   }
102
103   /**
104    * Processes the summary arguments for displaying.
105    *
106    * Some plugins alter the argument so it uses something else internally.
107    * For example the user validation set's the argument to the uid,
108    * for a faster query. But there are use cases where you want to use
109    * the old value again, for example the summary.
110    */
111   public function processSummaryArguments(&$args) {}
112
113   /**
114    * Returns a context definition for this argument.
115    *
116    * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface|null
117    *   A context definition that represents the argument or NULL if that is
118    *   not possible.
119    */
120   public function getContextDefinition() {}
121
122 }
123
124 /**
125  * @}
126  */