ArgumentValidatorPluginBase.php 2.67 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\argument_validator;
9

10
use Drupal\views\Plugin\views\PluginBase;
11

merlinofchaos's avatar
merlinofchaos committed
12 13 14 15 16 17 18 19 20 21 22
/**
 * @defgroup views_argument_validate_plugins Views argument validate plugins
 * @{
 * Allow specialized methods of validating arguments.
 *
 * @see hook_views_plugins()
 */

/**
 * Base argument validator plugin to provide basic functionality.
 */
23
abstract class ArgumentValidatorPluginBase extends PluginBase {
merlinofchaos's avatar
merlinofchaos committed
24 25 26 27 28

  /**
   * Initialize this plugin with the view and the argument
   * it is linked to.
   */
29
  public function init(&$view, &$argument, $options) {
30
    $this->setOptionDefaults($this->options, $this->defineOptions());
merlinofchaos's avatar
merlinofchaos committed
31 32 33
    $this->view = &$view;
    $this->argument = &$argument;

34
    $this->unpackOptions($this->options, $options);
merlinofchaos's avatar
merlinofchaos committed
35 36 37 38 39 40
  }

  /**
   * Retrieve the options when this is a new access
   * control plugin
   */
41
  protected function defineOptions() { return array(); }
merlinofchaos's avatar
merlinofchaos committed
42 43 44 45

  /**
   * Provide the default form for setting options.
   */
46
  public function buildOptionsForm(&$form, &$form_state) { }
merlinofchaos's avatar
merlinofchaos committed
47 48 49 50

  /**
   * Provide the default form form for validating options
   */
51
  public function validateOptionsForm(&$form, &$form_state) { }
merlinofchaos's avatar
merlinofchaos committed
52 53 54 55

  /**
   * Provide the default form form for submitting options
   */
56
  public function submitOptionsForm(&$form, &$form_state, &$options = array()) { }
merlinofchaos's avatar
merlinofchaos committed
57 58 59 60

  /**
   * Determine if the administrator has the privileges to use this plugin
   */
61
  public function access() { return TRUE; }
merlinofchaos's avatar
merlinofchaos committed
62 63 64 65 66

  /**
   * If we don't have access to the form but are showing it anyway, ensure that
   * the form is safe and cannot be changed from user input.
   *
67
   * This is only called by child objects if specified in the buildOptionsForm(),
merlinofchaos's avatar
merlinofchaos committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
   * so it will not always be used.
   */
  function check_access(&$form, $option_name) {
    if (!$this->access()) {
      $form[$option_name]['#disabled'] = TRUE;
      $form[$option_name]['#value'] = $form[$this->option_name]['#default_value'];
      $form[$option_name]['#description'] .= ' <strong>' . 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>';
    }
  }

  function validate_argument($arg) { return TRUE; }

  /**
   * Process the summary arguments for displaying.
   *
   * Some plugins alter the argument so it uses something else interal.
   * For example the user validation set's the argument to the uid,
   * for a faster query. But there are use cases where you want to use
   * the old value again, for example the summary.
   */
  function process_summary_arguments(&$args) { }
89

merlinofchaos's avatar
merlinofchaos committed
90 91 92 93 94
}

/**
 * @}
 */