function ArgumentPluginBase::defaultArgumentForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::defaultArgumentForm()
  2. 8.9.x core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::defaultArgumentForm()
  3. 10 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::defaultArgumentForm()

Provides a form for selecting the default argument.

This is used when the default action provides a default argument.

1 call to ArgumentPluginBase::defaultArgumentForm()
Date::defaultArgumentForm in core/modules/views/src/Plugin/views/argument/Date.php
Add an option to set the default value to the current date.
1 method overrides ArgumentPluginBase::defaultArgumentForm()
Date::defaultArgumentForm in core/modules/views/src/Plugin/views/argument/Date.php
Add an option to set the default value to the current date.

File

core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php, line 613

Class

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

Namespace

Drupal\views\Plugin\views\argument

Code

public function defaultArgumentForm(&$form, FormStateInterface $form_state) {
    $plugins = Views::pluginManager('argument_default')->getDefinitions();
    $options = [];
    $form['default_argument_type'] = [
        '#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
        '#suffix' => '</div>',
        '#type' => 'select',
        '#id' => 'edit-options-default-argument-type',
        '#title' => $this->t('Type'),
        '#default_value' => $this->options['default_argument_type'],
        '#states' => [
            'visible' => [
                ':input[name="options[default_action]"]' => [
                    'value' => 'default',
                ],
            ],
        ],
        // Views custom key, moves this element to the appropriate container
        // under the radio button.
'#argument_option' => 'default',
    ];
    foreach ($plugins as $id => $info) {
        if (!empty($info['no_ui'])) {
            continue;
        }
        $plugin = $this->getPlugin('argument_default', $id);
        if ($plugin) {
            if ($plugin->access() || $this->options['default_argument_type'] == $id) {
                $form['argument_default']['#argument_option'] = 'default';
                $form['argument_default'][$id] = [
                    '#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
                    '#suffix' => '</div>',
                    '#id' => 'edit-options-argument-default-options-' . $id,
                    '#type' => 'item',
                    // Even if the plugin has no options add the key to the form_state.
'#input' => TRUE,
                    '#states' => [
                        'visible' => [
                            ':input[name="options[default_action]"]' => [
                                'value' => 'default',
                            ],
                            ':input[name="options[default_argument_type]"]' => [
                                'value' => $id,
                            ],
                        ],
                    ],
                    '#default_value' => [],
                ];
                $options[$id] = $info['title'];
                $plugin->buildOptionsForm($form['argument_default'][$id], $form_state);
            }
        }
    }
    asort($options);
    $form['default_argument_type']['#options'] = $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.