3 namespace Drupal\views\Plugin\views\argument_default;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
7 use Drupal\views\Plugin\views\PluginBase;
10 * @defgroup views_argument_default_plugins Views argument default plugins
12 * Plugins for argument defaults in Views.
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.
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.
24 * @ingroup views_plugins
29 * The fixed argument default handler; also used as the base.
31 abstract class ArgumentDefaultPluginBase extends PluginBase {
34 * The argument handler instance associated with this plugin.
36 * @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase
41 * Return the default argument.
43 * This needs to be overridden by every default argument handler to properly do what is needed.
45 public function getArgument() { }
48 * Sets the parent argument this plugin is associated with.
50 * @param \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument
51 * The parent argument to set.
53 public function setArgument(ArgumentPluginBase $argument) {
54 $this->argument = $argument;
58 * Retrieve the options when this is a new access
61 protected function defineOptions() { return []; }
64 * Provide the default form for setting options.
66 public function buildOptionsForm(&$form, FormStateInterface $form_state) { }
69 * Provide the default form form for validating options
71 public function validateOptionsForm(&$form, FormStateInterface $form_state) { }
74 * Provide the default form form for submitting options
76 public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) { }
79 * Determine if the administrator has the privileges to use this
82 public function access() { return TRUE; }
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.
88 * This is only called by child objects if specified in the buildOptionsForm(),
89 * so it will not always be used.
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>';
102 public function getCacheTags() {