3 namespace Drupal\views\Plugin\views\argument_validator;
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_validate_plugins Views argument validate plugins
12 * Plugins for validating views contextual filters.
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.
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.
27 * @ingroup views_plugins
32 * Base argument validator plugin to provide basic functionality.
34 abstract class ArgumentValidatorPluginBase extends PluginBase {
37 * The argument handler instance associated with this plugin.
39 * @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase
44 * Sets the parent argument this plugin is associated with.
46 * @param \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument
47 * The parent argument to set.
49 public function setArgument(ArgumentPluginBase $argument) {
50 $this->argument = $argument;
54 * Retrieves the options when this is a new access control plugin.
56 protected function defineOptions() {
61 * Provides the default form for setting options.
63 public function buildOptionsForm(&$form, FormStateInterface $form_state) {}
66 * Provides the default form for validating options.
68 public function validateOptionsForm(&$form, FormStateInterface $form_state) {}
71 * Provides the default form for submitting options.
73 public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {}
76 * Determines if the administrator has the privileges to use this plugin.
78 public function access() {
83 * Blocks user input when the form is shown but we donĀ“t have access.
85 * This is only called by child objects if specified in the buildOptionsForm(),
86 * so it will not always be used.
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>';
97 * Performs validation for a given argument.
99 public function validateArgument($arg) {
104 * Processes the summary arguments for displaying.
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.
111 public function processSummaryArguments(&$args) {}
114 * Returns a context definition for this argument.
116 * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface|null
117 * A context definition that represents the argument or NULL if that is
120 public function getContextDefinition() {}