Version 1
[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() { return []; }
57
58   /**
59    * Provides the default form for setting options.
60    */
61   public function buildOptionsForm(&$form, FormStateInterface $form_state) { }
62
63   /**
64    * Provides the default form for validating options.
65    */
66   public function validateOptionsForm(&$form, FormStateInterface $form_state) { }
67
68   /**
69    * Provides the default form for submitting options.
70    */
71   public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) { }
72
73   /**
74    * Determines if the administrator has the privileges to use this plugin.
75    */
76   public function access() { return TRUE; }
77
78   /**
79    * Blocks user input when the form is shown but we donĀ“t have access.
80    *
81    * This is only called by child objects if specified in the buildOptionsForm(),
82    * so it will not always be used.
83    */
84   protected function checkAccess(&$form, $option_name) {
85     if (!$this->access()) {
86       $form[$option_name]['#disabled'] = TRUE;
87       $form[$option_name]['#value'] = $form[$this->option_name]['#default_value'];
88       $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>';
89     }
90   }
91
92   /**
93    * Performs validation for a given argument.
94    */
95   public function validateArgument($arg) { return TRUE; }
96
97   /**
98    * Processes the summary arguments for displaying.
99    *
100    * Some plugins alter the argument so it uses something else internally.
101    * For example the user validation set's the argument to the uid,
102    * for a faster query. But there are use cases where you want to use
103    * the old value again, for example the summary.
104    */
105   public function processSummaryArguments(&$args) { }
106
107   /**
108    * Returns a context definition for this argument.
109    *
110    * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface|null
111    *   A context definition that represents the argument or NULL if that is
112    *   not possible.
113    */
114   public function getContextDefinition() { }
115
116 }
117
118 /**
119  * @}
120  */