preClone not deleting Entity Reference field data (unless also deleting from $entity)

Created on 22 May 2019, over 5 years ago
Updated 21 March 2023, over 1 year ago

Got an issue with my CloneNodeEventSubscriber's preClone function. I use it to wipe out or alter certain fields before cloning. It works great on text fields, select fields (setting a value), or booleans (setting the value to 'false'). The form is generally:

    $cloned_entity = $event->getClonedEntity();
    $cloned_entity->set('field_my_field','my_value');

Where I'm having a problem is with attempting to wipe out the content of paragraphs fields (entity reference revisions). None of these tricks seem to work:

      unset($cloned_entity->field_my_paragraph);
      $cloned_entity->get('field_my_paragraph')->removeItem(0);
      $cloned_entity->set('field_my_paragraph',[]);

However, if I similarly try these tricks on $entity, and then run $entity->save();, the field empties out as I expect.

I tried following the debug trail to see what was going on, but as best I can tell, the changes to $cloned_entity get lost somewhere after the preClone is complete, in EntityCloneForm::submitForm().

Any hints or tricks to modify this kind of cloned content before it's saved? Has anyone tried this before?

🐛 Bug report
Status

Active

Component

Code

Created by

🇨🇦Canada TrevorBradley

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.71.5 2024