- Issue created by @partdigital
- First commit to issue fork.
- πΊπΈUnited States partdigital
partdigital β changed the visibility of the branch 3399716-add-a-method to hidden.
On our project we created a custom handler for saving cloned entities. We extended ContentEntityCloneBase and then overrode ContentEntityCloneBase::cloneEntity()
we only needed a few minor changes so we had to copy the most the code from the base class into our own handler. When we upgraded the module then we started seeing all sorts of odd behavior. That was because our version of ContentEntityCloneBase::cloneEntity
was outdated. We have to copy and modify that code again.
Note that we are using the Event subscribers as well but our use case also required us to create a custom handler.
Add in another function either right before $cloned_entity->save()
or perhaps have a function that contains that code itself. This will make it much safer for developers to write their own handlers.
/**
* Save the cloned entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param \Drupal\Core\Entity\EntityInterface $cloned_entity
* The cloned entity.
* @param array $properties
* The array of properties.
*/
protected function saveClonedEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = []) {
$cloned_entity->save();
}
I've attached a patch with an example but I'm open to any sort of idea.
Active
2.0
Code
partdigital β changed the visibility of the branch 3399716-add-a-method to hidden.