You are here

public function DataExport::submitOptionsForm in Views data export 8

Same name in this branch
  1. 8 src/Plugin/views/display/DataExport.php \Drupal\views_data_export\Plugin\views\display\DataExport::submitOptionsForm()
  2. 8 src/Plugin/views/style/DataExport.php \Drupal\views_data_export\Plugin\views\style\DataExport::submitOptionsForm()

Handle any special handling on the validate form.

Overrides RestExport::submitOptionsForm

File

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

Class

DataExport
Provides a data export display plugin.

Namespace

Drupal\views_data_export\Plugin\views\display

Code

public function submitOptionsForm(&$form, FormStateInterface $form_state) {
  parent::submitOptionsForm($form, $form_state);
  $section = $form_state
    ->get('section');
  switch ($section) {
    case 'displays':
      $this
        ->setOption($section, $form_state
        ->getValue($section));
      break;
    case 'export_method':
      $this
        ->setOption('export_method', $form_state
        ->getValue('export_method'));
      $batch_size = $form_state
        ->getValue('export_batch_size');
      $this
        ->setOption('export_batch_size', $batch_size > 1 ? $batch_size : 1);
      break;
    case 'export_limit':
      $limit = $form_state
        ->getValue('export_limit');
      $this
        ->setOption('export_limit', $limit > 0 ? $limit : 0);

      // Set the limit option on the pager as-well. This is used for the
      // standard rendering.
      $this
        ->setOption('pager', [
        'type' => 'some',
        'options' => [
          'items_per_page' => $limit,
          'offset' => 0,
        ],
      ]);
      break;
    case 'path':
      $this
        ->setOption('filename', $form_state
        ->getValue('filename'));
      $this
        ->setOption('automatic_download', $form_state
        ->getValue('automatic_download'));
      $this
        ->setOption('store_in_public_file_directory', $form_state
        ->getValue('store_in_public_file_directory'));

      // Adds slash if not in the redirect path if custom path is chosen.
      if ($form_state
        ->getValue('custom_redirect_path')) {
        $redirect_path = $form_state
          ->getValue('redirect_path');
        if ($redirect_path !== '' && $redirect_path[0] !== '/') {
          $redirect_path = '/' . $form_state
            ->getValue('redirect_path');
        }
        $this
          ->setOption('redirect_path', $redirect_path);
      }
      $this
        ->setOption('redirect_to_display', $form_state
        ->getValue('redirect_to_display'));
      $this
        ->setOption('custom_redirect_path', $form_state
        ->getValue('custom_redirect_path'));
      $this
        ->setOption('include_query_params', $form_state
        ->getValue('include_query_params'));
      break;
    case 'facet_settings':
      $this
        ->setOption('facet_settings', $form_state
        ->getValue('facet_settings'));
      break;
  }
}