You are here

public function DataExport::optionsSummary in Views data export 8

Provides the default summary for options in the views UI.

This output is returned as an array.

Overrides RestExport::optionsSummary

File

src/Plugin/views/display/DataExport.php, line 237

Class

DataExport
Provides a data export display plugin.

Namespace

Drupal\views_data_export\Plugin\views\display

Code

public function optionsSummary(&$categories, &$options) {
  parent::optionsSummary($categories, $options);

  // Doesn't make sense to have a pager for data export so remove it.
  unset($categories["pager"]);

  // Add a view configuration category for data export settings in the
  // second column.
  $categories['export_settings'] = [
    'title' => $this
      ->t('Export settings'),
    'column' => 'second',
    'build' => [
      '#weight' => 50,
    ],
  ];
  $options['export_method'] = [
    'category' => 'export_settings',
    'title' => $this
      ->t('Method'),
    'desc' => $this
      ->t('Change the way rows are processed.'),
  ];
  switch ($this
    ->getOption('export_method')) {
    case 'standard':
      $options['export_method']['value'] = $this
        ->t('Standard');
      break;
    case 'batch':
      $options['export_method']['value'] = $this
        ->t('Batch (size: @size)', [
        '@size' => $this
          ->getOption('export_batch_size'),
      ]);
      break;
  }
  $options['export_limit'] = [
    'category' => 'export_settings',
    'title' => $this
      ->t('Limit'),
    'desc' => $this
      ->t('The maximum amount of rows to export.'),
  ];
  $limit = $this
    ->getOption('export_limit');
  if ($limit) {
    $options['export_limit']['value'] = $this
      ->t('@nr rows', [
      '@nr' => $limit,
    ]);
  }
  else {
    $options['export_limit']['value'] = $this
      ->t('no limit');
  }
  $displays = array_filter($this
    ->getOption('displays'));
  if (count($displays) > 1) {
    $attach_to = $this
      ->t('Multiple displays');
  }
  elseif (count($displays) == 1) {
    $display = array_shift($displays);
    $displays = $this->view->storage
      ->get('display');
    if (!empty($displays[$display])) {
      $attach_to = $displays[$display]['display_title'];
    }
  }
  if (!isset($attach_to)) {
    $attach_to = $this
      ->t('None');
  }
  $options['displays'] = [
    'category' => 'path',
    'title' => $this
      ->t('Attach to'),
    'value' => $attach_to,
  ];
  if (\Drupal::service('module_handler')
    ->moduleExists('facets')) {

    // Add a view configuration category for data facet settings in the
    // second column.
    $categories['facet_settings'] = [
      'title' => $this
        ->t('Facet settings'),
      'column' => 'second',
      'build' => [
        '#weight' => 40,
      ],
    ];
    $facet_source = $this
      ->getOption('facet_settings');
    $options['facet_settings'] = [
      'category' => 'facet_settings',
      'title' => $this
        ->t('Facet source'),
      'value' => $facet_source,
    ];
  }

  // Add filename to the summary if set.
  if ($this
    ->getOption('filename')) {
    $options['path']['value'] .= $this
      ->t('(@filename)', [
      '@filename' => $this
        ->getOption('filename'),
    ]);
  }

  // Display the selected format from the style plugin if available.
  $style_options = $this
    ->getOption('style')['options'];
  if (!empty($style_options['formats'])) {
    $options['style']['value'] .= $this
      ->t('(@export_format)', [
      '@export_format' => reset($style_options['formats']),
    ]);
  }
}