function ArgumentPluginBase::buildOptionsForm
Same name in other branches
- 9 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::buildOptionsForm()
- 8.9.x core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::buildOptionsForm()
- 10 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::buildOptionsForm()
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 - NullArgument::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ argument/ NullArgument.php - NumericArgument::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ argument/ NumericArgument.php - StringArgument::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ argument/ StringArgument.php
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 - NullArgument::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ argument/ NullArgument.php - NumericArgument::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ argument/ NumericArgument.php
File
-
core/
modules/ views/ src/ Plugin/ views/ argument/ ArgumentPluginBase.php, line 218
Class
- ArgumentPluginBase
- Base class for argument (contextual filter) handler plugins.
Namespace
Drupal\views\Plugin\views\argumentCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$argument_text = $this->view->display_handler
->getArgumentText();
$form['#pre_render'][] = [
static::class,
'preRenderMoveArgumentOptions',
];
$form['description'] = [
'#markup' => $argument_text['description'],
'#theme_wrappers' => [
'container',
],
'#attributes' => [
'class' => [
'description',
],
],
];
$form['no_argument'] = [
'#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'] = [
'#weight' => 1000,
'#markup' => '<div class="clearfix"></div>',
];
$form['default_action'] = [
'#title' => $this->t('Default actions'),
'#title_display' => 'invisible',
'#type' => 'radios',
'#process' => [
[
$this,
'processContainerRadios',
],
],
'#default_value' => $this->options['default_action'],
'#fieldset' => 'no_argument',
];
$form['exception'] = [
'#type' => 'details',
'#title' => $this->t('Exceptions'),
'#fieldset' => 'no_argument',
];
$form['exception']['value'] = [
'#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'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override title'),
'#default_value' => $this->options['exception']['title_enable'],
];
$form['exception']['title'] = [
'#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' => [
'visible' => [
':input[name="options[exception][title_enable]"]' => [
'checked' => TRUE,
],
],
],
];
$options = [];
$defaults = $this->defaultActions();
$validate_options = [];
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'] = [
'#type' => 'details',
'#title' => $argument_text['filter value present'],
'#open' => TRUE,
];
$form['title_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override title'),
'#default_value' => $this->options['title_enable'],
'#fieldset' => 'argument_present',
];
$form['title'] = [
'#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' => [
'visible' => [
':input[name="options[title_enable]"]' => [
'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'] = [
'#type' => 'checkbox',
'#title' => $this->t('Specify validation criteria'),
'#default_value' => $this->options['specify_validation'],
'#fieldset' => 'argument_present',
];
$form['validate'] = [
'#type' => 'container',
'#fieldset' => 'argument_present',
];
// Validator options include derivatives with :. These are sanitized for js
// and reverted on submission.
$form['validate']['type'] = [
'#type' => 'select',
'#title' => $this->t('Validator'),
'#default_value' => static::encodeValidatorId($this->options['validate']['type']),
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => [
'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] = [
'#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.
// trick it into checking input to make #process run.
'#input' => TRUE,
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => [
'checked' => TRUE,
],
':input[name="options[validate][type]"]' => [
'value' => $sanitized_id,
],
],
],
'#id' => 'edit-options-validate-options-' . $sanitized_id,
'#default_value' => [],
];
$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'] = [
'#type' => 'select',
'#title' => $this->t('Action to take if filter value does not validate'),
'#default_value' => $this->options['validate']['fail'],
'#options' => $validate_options,
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'argument_present',
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.