Drupal - How do I delete an orphaned paragraph node?

In Drupal 8, you can still use entity_delete_multiple(), but it is marked as deprecated and it is going to be removed from Drupal 9.

It makes easy to remove those entities using Drush, for example, with the following code.

drush php-eval 'entity_delete_multiple("paragraph", [$id]);'

Even using code that works on Drupal 9, you would delete those entities in a single command line.

drush php-eval '$storage_handler = \Drupal::entityTypeManager()->getStorage($entity_type); $entities = $storage_handler->loadMultiple([$id]); $storage_handler->delete($entities);'

Replace $id with the ID of the entity you are going to delete. You can also delete multiple entities at once replacing [$id] with an array of IDs.


If you are not afraid to do it programmatically, you could use this code to load and delete the paragraph:

$entity = \Drupal::entityTypeManager()->getStorage('paragraph')->load($paragraph_id);
if ($entity) $entity->delete();

This is actually caused by the bug Removed paragraph entities are not deleted from database. When that gets fixed, this problem will stop getting worse (bloating our databases).

To remove all of this no-longer-relevant data in a clean standard way, we need to get a solution to [META] Remove obsolete composite entities from existing storage (garbage collection).

Rather than coming up with workarounds as suggested in other answers, patches for either (or both) of these issues would solve the issue permanently.

Tags:

8

Paragraphs