Moderation state is not copied

Created on 4 July 2024, 9 months ago

Problem/Motivation

When the entity in a channel is set up with moderation on both sites, the value of the moderation state is not copies and instead new entities on the client site have the default moderation state.

Steps to reproduce

Create the content type on both sites
Enable moderation with the default states on both sites
Create a channel for the content type on the source site
Set up the remote site on the client site
Set up this remote site with the Entity Reference processor
Create and publish a new node of the content type
Run a pull on that new piece of content from the client site
Go to the content page and notice that the new node is status Draft

Proposed resolution

The EntityReferece processor class skips fields that reference users or configuration. This is presumably to avoid copying users of configuration from one site to the other. However, it also does not copy the value.

Change the code to continue but not copy across the config or user. The rest of the code already checks to see if the reference exists so fields will still default if the referenced config or user entity does not exist on the client site.

Making this change changes the author of the new content from the current user to anonymous so an extra piece of code is needed to ensure that the new content is owned by the current user.

Remaining tasks

Complete and attach the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

3.0

Component

Entity Share Client

Created by

🇬🇧United Kingdom Rory Downes

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

Comments & Activities

  • Issue created by @Rory Downes
  • 🇬🇧United Kingdom Rory Downes

    This patch may not be the best solution but it works for me. Happy to discuss.

    Regards Rory

  • 🇬🇧United Kingdom Rory Downes

    I am not sure now about the owner reference - I need to test but it may be the module's behaviour anyway! I will test and adjust my patch accordingly when I get a moment! It occurs to me that the owner base field is probably not an entity reference class!

  • 🇬🇧United Kingdom Rory Downes

    The default behaviour of this code is to blank a field if there is nothing in the jsonapi.

    This happens with uid and the bundle field of a media entity. In the case of uid (which is not mandatory) this means it gets anonymous. In the case of the media entity bundle field this means that it causes a crash because bundle is a required field.

    So I have taken out the code to force the uid, leaving it as anonymous and put in a test to not put empty data into a mandatory field but instead leave it unchanged.

  • 🇬🇧United Kingdom Rory Downes

    I have now found that this patch does not work when running in the cron. It comes up with an error:
    Error: Call to a member function isRequired() on null in Drupal\entity_share_client\Plugin\EntityShareClient\Processor\EntityReference->processEntity() (line 194 of modules/contrib/entity_share/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/EntityReference.php).

    Also it occurs to me that these latest changes to my patch are possibly fixing bugs in the core. I did a quick search and could not find an existing issue.

    Anyway, it seems I have opened a can of worms with this approach so I am going to try to solve the problem that I reported with a new specific Processor plugin to specifically manage moderation state.

  • 🇬🇧United Kingdom Rory Downes

    OK, now I have a patch creating a new, optional processor. It checks to ensure the following:

    1. The workbench moderation module is installed
    2. The entity is moderated
    3. The data from the source contains a moderation state
    4. This moderation state exists in the client site

    As this is a completely different approach, I have not supplied an interdiff.

  • Status changed to Needs review 8 days ago
  • 🇬🇧United Kingdom joachim
Production build 0.71.5 2024