You are here

public function ContentDelete::submitForm in Delete all 8

Same name and namespace in other branches
  1. 2.x src/Form/ContentDelete.php \Drupal\delete_all\Form\ContentDelete::submitForm()

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/ContentDelete.php, line 94

Class

ContentDelete
Create a Form for deleting all content.

Namespace

Drupal\delete_all\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $delete_all_checkbox = $form_state
    ->getValue([
    'select_all',
  ]);
  $all_content_type = array_keys($this
    ->getAvailableNodeType());
  $selected_node_type = $form_state
    ->getValue('node_type');
  $contentDeleteController = new ContentDeleteController();
  if ($delete_all_checkbox == 1) {
    $nodes_to_delete = $contentDeleteController
      ->getContentToDelete($all_content_type);
  }
  else {
    $nodes_to_delete = $contentDeleteController
      ->getContentToDelete([
      $selected_node_type,
    ]);
  }
  if ($nodes_to_delete) {
    $batch = $contentDeleteController
      ->getContentDeleteBatch($nodes_to_delete);
    batch_set($batch);
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('No node found'));
  }
}