You are here

public function ViewsBulkOperationsBulkForm::viewsFormSubmit in Views Bulk Operations (VBO) 8.2

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. 4.0.x 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 758

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_id = $form_state
      ->getValue('action');
    $action = $this->actions[$action_id];
    $this->tempStoreData['action_id'] = $action_id;
    $this->tempStoreData['action_label'] = empty($this->options['preconfiguration'][$action_id]['label_override']) ? (string) $action['label'] : $this->options['preconfiguration'][$action_id]['label_override'];
    $this->tempStoreData['relationship_id'] = $this->options['relationship'];
    $this->tempStoreData['preconfiguration'] = isset($this->options['preconfiguration'][$action_id]) ? $this->options['preconfiguration'][$action_id] : [];
    if (!$form_state
      ->getValue('select_all')) {

      // Update list data with the current form selection.
      foreach ($form_state
        ->getValue($this->options['id']) as $row_index => $bulkFormKey) {
        if ($bulkFormKey) {
          $this->tempStoreData['list'][$bulkFormKey] = $this
            ->getListItem($bulkFormKey, $form[$this->options['id']][$row_index]['#title']);
        }
        else {
          unset($this->tempStoreData['list'][$form[$this->options['id']][$row_index]['#return_value']]);
        }
      }
    }
    else {

      // Unset the list completely.
      $this->tempStoreData['list'] = [];
    }
    $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();
      }
    }

    // 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 ($this->options['batch']) {
      if (!empty($action['confirm_form_route_name'])) {
        $redirect_route = $action['confirm_form_route_name'];
      }
    }
    elseif (!empty($action['confirm_form_route_name'])) {
      $redirect_route = $action['confirm_form_route_name'];
    }

    // 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']);
    }
  }
}