How do we know an entity is cloned

Created on 13 June 2019, over 5 years ago
Updated 19 October 2023, about 1 year ago

I have implemented an entity presave hook to process a file field attached to a node. However, I don't want to do this processing when a node is cloned. I can subscribe to the presave clone event, but I don't see how I can use that with the entity presave hook.

I've looked to see if there's a property on the entity that indicates it's a clone, but I don't such a thing. Any ideas how I might do this?

πŸ’¬ Support request
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States chris_riddell

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.

  • Hi, hi have the same question, any news about this?

  • At present there doesn't seem to be a built-in way to track this.

    I've solved this in my project by adding an entity reference field named "field_source_entity".
    That field that stays empty on entities that get cloned, and automatically gets populated on cloned entities through a custom EventSubscriber that listens to the 'entity_clone.post_clone' event and sets $clone->field_source_entity to $original->id().

Production build 0.71.5 2024