Problem/Motivation

Steps to reproduce

  1. Make new paragraph type with just 1 field
  2. Connect that type to content type node
  3. Fill data to node
  4. List records in VIEWs - data source paragraph, fields:ID, parent name, parent type, ...
  5. Delete one item (row) from collection connected (paragraph type) to node
  6. See VIEW again - item deleted item exists

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork paragraphs-3509430

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marianrk created an issue. See original summary.

arunsahijpal’s picture

Assigned: Unassigned » arunsahijpal

Working on it.

arunsahijpal’s picture

Assigned: arunsahijpal » Unassigned
Status: Active » Needs review

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

divyansh.gupta’s picture

Status: Needs review » Reviewed & tested by the community

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!!

danyg’s picture

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');
    }
danyg’s picture

Status: Reviewed & tested by the community » Needs work
danyg’s picture

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.

anybody’s picture

Version: 8.x-1.18 » 8.x-1.x-dev

I can confirm this issue, but maybe it's a duplicate or subissue of #2771531: [META] Remove obsolete composite entities from existing storage (garbage collection)