- 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:
- The workbench moderation module is installed
- The entity is moderated
- The data from the source contains a moderation state
- 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
3 months ago 12:10pm 1 April 2025 - 🇬🇧United Kingdom joachim
Thanks for the patch.
Needs a bit of work -- also, could you use a MR rather than uploading patches please?
-
+++ b/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/ModerationStateProcessor.php @@ -0,0 +1,64 @@ + * label = @Translation("Moderation State Processor"),
Sentence case rather than title case.
-
+++ b/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/ModerationStateProcessor.php @@ -0,0 +1,64 @@ +{
Code formatting.
-
+++ b/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/ModerationStateProcessor.php @@ -0,0 +1,64 @@ + if ($processed_entity->hasField('moderation_state')) {
Somewhat a personal preference, but I think it's easier to read with the return early pattern.
-