0

Is there a way of getting a second object for an entity that is a different PHP object (with different PHP objects inside as well)?

I tried using https://github.com/myclabs/DeepCopy with a node entity object, and it crashed having exhausted 1GB of memory.

2
  • 3
    clone $entity clones the entity object with cloned fields and field items. Isn't that a second object with different objects inside?
    – 4uk4
    Commented May 15 at 19:35
  • Thanks! I had no idea entity objects supported that. Feel free to put that as an answer to get credit :)
    – joachim
    Commented May 17 at 10:46

1 Answer 1

2

You can use the PHP standard clone operator:

$clone = clone $entity;

The base class for content entities implements the magic method ContentEntityBase::__clone() to deep clone the entity including the field objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.