Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / argument_default / ArgumentDefaultPluginBase.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\argument_default;
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_default_plugins Views argument default plugins
11  * @{
12  * Plugins for argument defaults in Views.
13  *
14  * Argument default plugins provide default values for contextual filters. This
15  * can be useful for blocks and other display types lacking a natural argument
16  * input. Examples are plugins to extract node and user IDs from the URL.
17  *
18  * Argument default plugins extend
19  * \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase. They
20  * must be annotated with \Drupal\views\Annotation\ViewsArgumentDefault
21  * annotation, and they must be in namespace directory
22  * Plugin\views\argument_default.
23  *
24  * @ingroup views_plugins
25  * @see plugin_api
26  */
27
28 /**
29  * The fixed argument default handler; also used as the base.
30  */
31 abstract class ArgumentDefaultPluginBase extends PluginBase {
32
33   /**
34    * The argument handler instance associated with this plugin.
35    *
36    * @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase
37    */
38   protected $argument;
39
40   /**
41    * Return the default argument.
42    *
43    * This needs to be overridden by every default argument handler to properly do what is needed.
44    */
45   public function getArgument() { }
46
47   /**
48    * Sets the parent argument this plugin is associated with.
49    *
50    * @param \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument
51    *   The parent argument to set.
52    */
53   public function setArgument(ArgumentPluginBase $argument) {
54     $this->argument = $argument;
55   }
56
57   /**
58    * Retrieve the options when this is a new access
59    * control plugin
60    */
61   protected function defineOptions() { return []; }
62
63   /**
64    * Provide the default form for setting options.
65    */
66   public function buildOptionsForm(&$form, FormStateInterface $form_state) { }
67
68   /**
69    * Provide the default form form for validating options
70    */
71   public function validateOptionsForm(&$form, FormStateInterface $form_state) { }
72
73   /**
74    * Provide the default form form for submitting options
75    */
76   public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) { }
77
78   /**
79    * Determine if the administrator has the privileges to use this
80    * plugin
81    */
82   public function access() { return TRUE; }
83
84   /**
85    * If we don't have access to the form but are showing it anyway, ensure that
86    * the form is safe and cannot be changed from user input.
87    *
88    * This is only called by child objects if specified in the buildOptionsForm(),
89    * so it will not always be used.
90    */
91   protected function checkAccess(&$form, $option_name) {
92     if (!$this->access()) {
93       $form[$option_name]['#disabled'] = TRUE;
94       $form[$option_name]['#value'] = $form[$this->option_name]['#default_value'];
95       $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>';
96     }
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   public function getCacheTags() {
103     return [];
104   }
105
106 }
107
108 /**
109  * @}
110  */