public function ParagraphsTypeDeleteConfirm::deleteExistingEntities in Paragraphs 8
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
- src/
Form/ ParagraphsTypeDeleteConfirm.php, line 48
Class
- ParagraphsTypeDeleteConfirm
- Provides a form for Paragraphs type deletion.
Namespace
Drupal\paragraphs\FormCode
public function deleteExistingEntities(array $form, FormStateInterface $form_state) {
$storage = $this->entityTypeManager
->getStorage('paragraph');
$ids = $storage
->getQuery()
->condition('type', $this->entity
->id())
->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();
}