public function ArgumentPluginBase::defaultSummaryForm

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

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php, line 565
Definition of Drupal\views\Plugin\views\argument\ArgumentPluginBase.

Class

ArgumentPluginBase
Base class for arguments.

Namespace

Drupal\views\Plugin\views\argument

Code

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