- Issue created by @marianrk
- Merge request !178Issue #3509430: Added hook for paragraph deletion. → (Open) created by arunsahijpal
- 🇮🇳India arunsahijpal
Hi @marianrk,
I've added a hook_entity_update to delete the referenced paragraphs please check.
Also @berdir please check whether this should be the part of module behaviour or not.Thanks,
Arun - Status changed to RTBC
about 1 month ago 6:15am 11 July 2025 - 🇮🇳India divyansh.gupta Jaipur
I was successfully able to reproduce the issue and the MR applied successfully and solved the issue where if we are deleting a row from content then it is also removed from view page,
The changes looks good to me, thus moving this to RTBC!! - 🇭🇺Hungary danyg Budapest
The query condition doesn't check the parent_id. If you have multiple node types with with many different paragraphs, you may face a big problem on a single node update. Add parent_id check to the code:
if (!empty($referenced_paragraph_ids)) { $query->condition('parent_id', $entity->id()); $query->condition('id', $referenced_paragraph_ids, 'NOT IN'); }
- 🇭🇺Hungary danyg Budapest
Sorry, my bad, the correct code is
// Find all orphaned paragraphs (paragraphs that are not referenced anymore). $paragraph_storage = \Drupal::entityTypeManager()->getStorage('paragraph'); $query = $paragraph_storage->getQuery()->accessCheck(FALSE); $query->condition('parent_id', $entity->id()); if (!empty($referenced_paragraph_ids)) { $query->condition('id', $referenced_paragraph_ids, 'NOT IN'); } $orphaned_paragraph_ids = $query->execute();
The parent_id has to be checked every time, not only if $referenced_paragraph_ids is not empty. Without that, all paragraphs can be removed accidentally.