You are here

public function ArgumentPluginBase::buildOptionsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides HandlerBase::buildOptionsForm

5 calls to ArgumentPluginBase::buildOptionsForm()
IndexTidDepth::buildOptionsForm in core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepth.php
Provide a form to edit options for this plugin.
ManyToOne::buildOptionsForm in core/modules/views/src/Plugin/views/argument/ManyToOne.php
Provide a form to edit options for this plugin.
NullArgument::buildOptionsForm in core/modules/views/src/Plugin/views/argument/NullArgument.php
Override buildOptionsForm() so that only the relevant options are displayed to the user.
NumericArgument::buildOptionsForm in core/modules/views/src/Plugin/views/argument/NumericArgument.php
Provide a form to edit options for this plugin.
StringArgument::buildOptionsForm in core/modules/views/src/Plugin/views/argument/StringArgument.php
Provide a form to edit options for this plugin.
6 methods override ArgumentPluginBase::buildOptionsForm()
IndexTidDepth::buildOptionsForm in core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepth.php
Provide a form to edit options for this plugin.
IndexTidDepthModifier::buildOptionsForm in core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepthModifier.php
Provide a form to edit options for this plugin.
ManyToOne::buildOptionsForm in core/modules/views/src/Plugin/views/argument/ManyToOne.php
Provide a form to edit options for this plugin.
NullArgument::buildOptionsForm in core/modules/views/src/Plugin/views/argument/NullArgument.php
Override buildOptionsForm() so that only the relevant options are displayed to the user.
NumericArgument::buildOptionsForm in core/modules/views/src/Plugin/views/argument/NumericArgument.php
Provide a form to edit options for this plugin.

... See full list

File

core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php, line 157
Contains \Drupal\views\Plugin\views\argument\ArgumentPluginBase.

Class

ArgumentPluginBase
Base class for argument (contextual filter) handler plugins.

Namespace

Drupal\views\Plugin\views\argument

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $argument_text = $this->view->display_handler
    ->getArgumentText();
  $form['#pre_render'][] = array(
    get_class($this),
    'preRenderMoveArgumentOptions',
  );
  $form['description'] = array(
    '#markup' => $argument_text['description'],
    '#theme_wrappers' => array(
      'container',
    ),
    '#attributes' => array(
      'class' => array(
        'description',
      ),
    ),
  );
  $form['no_argument'] = array(
    '#type' => 'details',
    '#title' => $argument_text['filter value not present'],
    '#open' => TRUE,
  );

  // Everything in the details is floated, so the last element needs to
  // clear those floats.
  $form['no_argument']['clearfix'] = array(
    '#weight' => 1000,
    '#markup' => '<div class="clearfix"></div>',
  );
  $form['default_action'] = array(
    '#title' => $this
      ->t('Default actions'),
    '#title_display' => 'invisible',
    '#type' => 'radios',
    '#process' => array(
      array(
        $this,
        'processContainerRadios',
      ),
    ),
    '#default_value' => $this->options['default_action'],
    '#fieldset' => 'no_argument',
  );
  $form['exception'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Exceptions'),
    '#fieldset' => 'no_argument',
  );
  $form['exception']['value'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Exception value'),
    '#size' => 20,
    '#default_value' => $this->options['exception']['value'],
    '#description' => $this
      ->t('If this value is received, the filter will be ignored; i.e, "all values"'),
  );
  $form['exception']['title_enable'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Override title'),
    '#default_value' => $this->options['exception']['title_enable'],
  );
  $form['exception']['title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Override title'),
    '#title_display' => 'invisible',
    '#size' => 20,
    '#default_value' => $this->options['exception']['title'],
    '#description' => $this
      ->t('Override the view and other argument titles. You may use Twig syntax in this field as well as the "arguments" and "raw_arguments" arrays.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[exception][title_enable]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $options = array();
  $defaults = $this
    ->defaultActions();
  $validate_options = array();
  foreach ($defaults as $id => $info) {
    $options[$id] = $info['title'];
    if (empty($info['default only'])) {
      $validate_options[$id] = $info['title'];
    }
    if (!empty($info['form method'])) {
      $this
        ->{$info['form method']}($form, $form_state);
    }
  }
  $form['default_action']['#options'] = $options;
  $form['argument_present'] = array(
    '#type' => 'details',
    '#title' => $argument_text['filter value present'],
    '#open' => TRUE,
  );
  $form['title_enable'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Override title'),
    '#default_value' => $this->options['title_enable'],
    '#fieldset' => 'argument_present',
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Provide title'),
    '#title_display' => 'invisible',
    '#default_value' => $this->options['title'],
    '#description' => $this
      ->t('Override the view and other argument titles. You may use Twig syntax in this field.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[title_enable]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#fieldset' => 'argument_present',
  );
  $output = $this
    ->getTokenHelp();
  $form['token_help'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Replacement patterns'),
    '#value' => $output,
    '#states' => [
      'visible' => [
        [
          ':input[name="options[title_enable]"]' => [
            'checked' => TRUE,
          ],
        ],
        [
          ':input[name="options[exception][title_enable]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $form['specify_validation'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Specify validation criteria'),
    '#default_value' => $this->options['specify_validation'],
    '#fieldset' => 'argument_present',
  );
  $form['validate'] = array(
    '#type' => 'container',
    '#fieldset' => 'argument_present',
  );

  // Validator options include derivatives with :. These are sanitized for js
  // and reverted on submission.
  $form['validate']['type'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Validator'),
    '#default_value' => static::encodeValidatorId($this->options['validate']['type']),
    '#states' => array(
      'visible' => array(
        ':input[name="options[specify_validation]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $plugins = Views::pluginManager('argument_validator')
    ->getDefinitions();
  foreach ($plugins as $id => $info) {
    if (!empty($info['no_ui'])) {
      continue;
    }
    $valid = TRUE;
    if (!empty($info['type'])) {
      $valid = FALSE;
      if (empty($this->definition['validate type'])) {
        continue;
      }
      foreach ((array) $info['type'] as $type) {
        if ($type == $this->definition['validate type']) {
          $valid = TRUE;
          break;
        }
      }
    }

    // If we decide this validator is ok, add it to the list.
    if ($valid) {
      $plugin = $this
        ->getPlugin('argument_validator', $id);
      if ($plugin) {
        if ($plugin
          ->access() || $this->options['validate']['type'] == $id) {

          // Sanitize ID for js.
          $sanitized_id = static::encodeValidatorId($id);
          $form['validate']['options'][$sanitized_id] = array(
            '#prefix' => '<div id="edit-options-validate-options-' . $sanitized_id . '-wrapper">',
            '#suffix' => '</div>',
            '#type' => 'item',
            // Even if the plugin has no options add the key to the form_state.
            '#input' => TRUE,
            // trick it into checking input to make #process run
            '#states' => array(
              'visible' => array(
                ':input[name="options[specify_validation]"]' => array(
                  'checked' => TRUE,
                ),
                ':input[name="options[validate][type]"]' => array(
                  'value' => $sanitized_id,
                ),
              ),
            ),
            '#id' => 'edit-options-validate-options-' . $sanitized_id,
            '#default_value' => array(),
          );
          $plugin
            ->buildOptionsForm($form['validate']['options'][$sanitized_id], $form_state);
          $validate_types[$sanitized_id] = $info['title'];
        }
      }
    }
  }
  asort($validate_types);
  $form['validate']['type']['#options'] = $validate_types;
  $form['validate']['fail'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Action to take if filter value does not validate'),
    '#default_value' => $this->options['validate']['fail'],
    '#options' => $validate_options,
    '#states' => array(
      'visible' => array(
        ':input[name="options[specify_validation]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#fieldset' => 'argument_present',
  );
}