Remove orphan paragraphs when host entity is removed

Created on 24 May 2019, about 5 years ago
Updated 20 October 2023, 8 months ago

I know that probably this issue is duplicate of something which already exist. At least I've found these issues somehow related to this problem:

But as I understand there is no final decision in any of them.

Problem/Motivation

So, let's say you have a node with the entity_reference_revisions field which references to paragraphs. When that node is remove the paragraph is still exist in db. And if we're doing queries without relating to the host entity - they give a results. That's correct for views and for entity queries. From the discussions in the issues I've listed above I understood that "It's not paragraphs responsibility, the entity_reference_revisions should clean up the garbage". But what I see in paragraphs entity: it has two fields - parent_type and parent_id which point to the host entity. They can point to only one entity, so it's illogical to assume that one paragraph can be used in several nodes. So when deleting host node - we can delete paragraph safely.

Another thing which I don't understand: the parent_type and parent_id can be NULL in db. Why? That means paragraph can exist without any host entity? But why we don't have UI to manage paragraph entities then? When I'm checking the db on the project - I can't find any paragraphs with parent_type=NULL and parent_id=NULL.

Proposed resolution

I think removing the paragraph when removing host entity is the correct way. It was suggested by @recrit in Remove orphan paragraphs β†’ . And I think it should be a part of paragraphs module. It work perfectly on one of my projects.

I'm sure there are people who disagree with that, I would be appreciated if anyone can explain why this approach does not work or it's incorrect (if it's already described somewhere, that's ok but please give the reference and "there are many issues already").

Remaining tasks

Reviews and clarifications needed.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine mpolishchuck

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024