function ArgumentPluginBase::defaultSummaryForm

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

Provide a form for selecting further summary options when the default action is set to display one.

File

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

Class

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

Namespace

Drupal\views\Plugin\views\argument

Code

public function defaultSummaryForm(&$form, FormStateInterface $form_state) {
    $style_plugins = Views::pluginManager('style')->getDefinitions();
    $summary_plugins = [];
    $format_options = [];
    foreach ($style_plugins as $key => $plugin) {
        if (isset($plugin['display_types']) && in_array('summary', $plugin['display_types'])) {
            $summary_plugins[$key] = $plugin;
            $format_options[$key] = $plugin['title'];
        }
    }
    $form['summary'] = [
        // Views custom key, moves this element to the appropriate container
        // under the radio button.
'#argument_option' => 'summary',
    ];
    $form['summary']['sort_order'] = [
        '#type' => 'radios',
        '#title' => $this->t('Sort order'),
        '#options' => [
            'asc' => $this->t('Ascending'),
            'desc' => $this->t('Descending'),
        ],
        '#default_value' => $this->options['summary']['sort_order'],
        '#states' => [
            'visible' => [
                ':input[name="options[default_action]"]' => [
                    'value' => 'summary',
                ],
            ],
        ],
    ];
    $form['summary']['number_of_records'] = [
        '#type' => 'radios',
        '#title' => $this->t('Sort by'),
        '#default_value' => $this->options['summary']['number_of_records'],
        '#options' => [
            0 => $this->getSortName(),
            1 => $this->t('Number of records'),
        ],
        '#states' => [
            'visible' => [
                ':input[name="options[default_action]"]' => [
                    'value' => 'summary',
                ],
            ],
        ],
    ];
    $form['summary']['format'] = [
        '#type' => 'radios',
        '#title' => $this->t('Format'),
        '#options' => $format_options,
        '#default_value' => $this->options['summary']['format'],
        '#states' => [
            'visible' => [
                ':input[name="options[default_action]"]' => [
                    'value' => 'summary',
                ],
            ],
        ],
    ];
    foreach ($summary_plugins as $id => $info) {
        $plugin = $this->getPlugin('style', $id);
        if (!$plugin->usesOptions()) {
            continue;
        }
        if ($plugin) {
            $form['summary']['options'][$id] = [
                '#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
                '#suffix' => '</div>',
                '#id' => 'edit-options-summary-options-' . $id,
                '#type' => 'item',
                // Trick it into checking input to make #process run.
'#input' => TRUE,
                '#states' => [
                    'visible' => [
                        ':input[name="options[default_action]"]' => [
                            'value' => 'summary',
                        ],
                        ':input[name="options[summary][format]"]' => [
                            'value' => $id,
                        ],
                    ],
                ],
                '#default_value' => [],
            ];
            $options[$id] = $info['title'];
            $plugin->buildOptionsForm($form['summary']['options'][$id], $form_state);
        }
    }
}

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