You are here

public function ViewsBulkOperationsBulkForm::viewsFormSubmit in Views Bulk Operations (VBO) 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/field/ViewsBulkOperationsBulkForm.php \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm::viewsFormSubmit()
  2. 8 src/Plugin/views/field/ViewsBulkOperationsBulkForm.php \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm::viewsFormSubmit()
  3. 8.2 src/Plugin/views/field/ViewsBulkOperationsBulkForm.php \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm::viewsFormSubmit()

Submit handler for the bulk form.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Plugin/views/field/ViewsBulkOperationsBulkForm.php, line 886

Class

ViewsBulkOperationsBulkForm
Defines the Views Bulk Operations field plugin.

Namespace

Drupal\views_bulk_operations\Plugin\views\field

Code

public function viewsFormSubmit(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->get('step') == 'views_form_views_form') {
    $action_config = $this->options['selected_actions'][$form_state
      ->getValue('action')];
    $action = $this->actions[$action_config['action_id']];
    $this->tempStoreData['action_id'] = $action_config['action_id'];
    $this->tempStoreData['action_label'] = empty($action_config['preconfiguration']['label_override']) ? (string) $action['label'] : $action_config['preconfiguration']['label_override'];
    $this->tempStoreData['relationship_id'] = $this->options['relationship'];
    $this->tempStoreData['preconfiguration'] = isset($action_config['preconfiguration']) ? $action_config['preconfiguration'] : [];
    $this->tempStoreData['clear_on_exposed'] = $this->options['clear_on_exposed'];
    $this->tempStoreData['confirm_route'] = $action['confirm_form_route_name'];
    if (empty($this->tempStoreData['confirm_route']) && !empty($action_config['preconfiguration']['add_confirmation'])) {
      $this->tempStoreData['confirm_route'] = 'views_bulk_operations.confirm';
    }
    $configurable = $this
      ->isActionConfigurable($action);

    // Get configuration if using AJAX.
    if ($configurable && empty($this->options['form_step'])) {
      $actionObject = $this->actionManager
        ->createInstance($action_id);
      if (method_exists($actionObject, 'submitConfigurationForm')) {
        $actionObject
          ->submitConfigurationForm($form, $form_state);
        $this->tempStoreData['configuration'] = $actionObject
          ->getConfiguration();
      }
      else {
        $form_state
          ->cleanValues();
        $this->tempStoreData['configuration'] = $form_state
          ->getValues();
      }
    }

    // Update list data with the current page selection.
    $selected_keys = [];
    $input = $form_state
      ->getUserInput();
    foreach ($input[$this->options['id']] as $row_index => $bulk_form_key) {
      $selected_keys[$bulk_form_key] = $bulk_form_key;
    }
    $select_all = $form_state
      ->getValue('select_all');
    foreach ($this->tempStoreData['bulk_form_keys'] as $bulk_form_key) {
      if (isset($selected_keys[$bulk_form_key]) && !$select_all || !isset($selected_keys[$bulk_form_key]) && $select_all) {
        $this->tempStoreData['list'][$bulk_form_key] = $this
          ->getListItem($bulk_form_key);
      }
      else {
        unset($this->tempStoreData['list'][$bulk_form_key]);
      }
    }

    // Update exclude mode setting.
    $this->tempStoreData['exclude_mode'] = !empty($select_all);

    // Routing - determine redirect route.
    //
    // Set default redirection due to issue #2952498.
    // @todo remove the next line when core cause is eliminated.
    $redirect_route = 'views_bulk_operations.execute_batch';
    if ($this->options['form_step'] && $configurable) {
      $redirect_route = 'views_bulk_operations.execute_configurable';
    }
    elseif (!empty($this->tempStoreData['confirm_route'])) {
      $redirect_route = $this->tempStoreData['confirm_route'];
    }

    // Redirect if needed.
    if (!empty($redirect_route)) {
      $this
        ->setTempstoreData($this->tempStoreData);
      $form_state
        ->setRedirect($redirect_route, [
        'view_id' => $this->view
          ->id(),
        'display_id' => $this->view->current_display,
      ]);
    }
    else {
      $this
        ->deleteTempstoreData();
      $this->actionProcessor
        ->executeProcessing($this->tempStoreData, $this->view);
      $form_state
        ->setRedirectUrl($this->tempStoreData['redirect_url']);
    }
  }
}