You are here

public function PathautoAdminDelete::submitForm in Pathauto 8

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/PathautoAdminDelete.php, line 121

Class

PathautoAdminDelete
Alias mass delete form.

Namespace

Drupal\pathauto\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $delete_all = $form_state
    ->getValue([
    'delete',
    'all_aliases',
  ]);

  // Keeping custom aliases forces us to go the slow way to correctly check
  // the automatic/manual flag.
  if ($form_state
    ->getValue([
    'options',
    'keep_custom_aliases',
  ])) {
    $batch = [
      'title' => $this
        ->t('Bulk deleting URL aliases'),
      'operations' => [
        [
          'Drupal\\pathauto\\Form\\PathautoAdminDelete::batchStart',
          [
            $delete_all,
          ],
        ],
      ],
      'finished' => 'Drupal\\pathauto\\Form\\PathautoAdminDelete::batchFinished',
    ];
    if ($delete_all) {
      foreach (array_keys($form_state
        ->getValue([
        'delete',
        'plugins',
      ])) as $id) {
        $batch['operations'][] = [
          'Drupal\\pathauto\\Form\\PathautoAdminDelete::batchProcess',
          [
            $id,
          ],
        ];
      }
    }
    else {
      foreach (array_keys(array_filter($form_state
        ->getValue([
        'delete',
        'plugins',
      ]))) as $id) {
        $batch['operations'][] = [
          'Drupal\\pathauto\\Form\\PathautoAdminDelete::batchProcess',
          [
            $id,
          ],
        ];
      }
    }
    batch_set($batch);
  }
  elseif ($delete_all) {
    $this->aliasStorageHelper
      ->deleteAll();
    $this
      ->messenger()
      ->addMessage($this
      ->t('All of your path aliases have been deleted.'));
  }
  else {
    foreach (array_keys(array_filter($form_state
      ->getValue([
      'delete',
      'plugins',
    ]))) as $id) {
      $alias_type = $this->aliasTypeManager
        ->createInstance($id);
      $this->aliasStorageHelper
        ->deleteBySourcePrefix((string) $alias_type
        ->getSourcePrefix());
      $this
        ->messenger()
        ->addMessage($this
        ->t('All of your %label path aliases have been deleted.', [
        '%label' => $alias_type
          ->getLabel(),
      ]));
    }
  }
}