public function ParagraphsTypeDeleteConfirm::deleteExistingEntities

Form submit callback to delete paragraphs.

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

paragraphs/src/Form/ParagraphsTypeDeleteConfirm.php, line 49

Class

ParagraphsTypeDeleteConfirm
Provides a form for Paragraphs type deletion.

Namespace

Drupal\paragraphs\Form

Code

public function deleteExistingEntities(array $form, FormStateInterface $form_state) {
  $storage = $this->entityTypeManager
    ->getStorage('paragraph');
  $ids = $storage
    ->getQuery()
    ->condition('type', $this->entity
    ->id())
    ->accessCheck(FALSE)
    ->execute();
  if (!empty($ids)) {
    $paragraphs = Paragraph::loadMultiple($ids);

    // Delete existing entities.
    $storage
      ->delete($paragraphs);
    $this
      ->messenger()
      ->addMessage($this
      ->formatPlural(count($paragraphs), 'Entity is successfully deleted.', 'All @count entities are successfully deleted.'));
  }

  // Set form to rebuild.
  $form_state
    ->setRebuild();
}