Node revision is getting created multiple times on node save when group relationship added programmatically

Created on 30 October 2023, about 1 year ago
Updated 9 February 2024, 10 months ago

Problem/Motivation

I am on D10 with group module enabled, I have a group entity reference field in a Article content type.
I am programmatically adding a relationship for the group selected in the entity reference field when the node is getting saved.
Now the issue is after node is saved D10 is creating revisions multiple times.

I can confirm that when group module is disabled, revisions are creating properly.

Steps to reproduce

1. Enable group module on D10.
2. Add as entity reference field in Article content type.
3. Below code used to make the bridge between node and group entity.

$pluginId = 'group_' . $entity->getEntityTypeId() . ':' . $entity->bundle();
      $relation = $group->getRelationshipsByEntity($entity,$pluginId);
      if (empty($relation)) {
        $group->addRelationship($entity, $pluginId);
      }

Note: Looking for a quick solution, thanks in Advance.

Proposed resolution

Remaining tasks

<?php

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Raghav kumar

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

Comments & Activities

  • Issue created by @Raghav kumar
  • πŸ‡ΊπŸ‡ΈUnited States Raghav kumar
  • πŸ‡©πŸ‡ͺGermany Tomefa Dresden

    Same problem for me, it is because of the re-save of the entity in the group module.
    See this ticket: https://www.drupal.org/project/group/issues/2872697 πŸ› Node update hook is triggered upon group content create Needs work

    But when using the patch in the other ticket + content moderation, then the revisions are messed up.

    For now, i have let the multiple revision be create and add a function that remove duplicate revisions created at the same time, to keep only 1 revision. It's sad to come at this point but i didn't find a proper fix for this problem.

    Seems like group will not remove the re-saved entity code.

Production build 0.71.5 2024