replicateEntityEvent does not pass in the duplicate entity

Created on 6 October 2023, 9 months ago

Problem/Motivation

I'm not sure if this is a feature or a bug, but in: \Drupal\replicate\Replicator::cloneEntity we have:


  public function cloneEntity(EntityInterface $entity) {
    if ($clone = $entity->createDuplicate()) {
      $event = new ReplicateEntityEvent($entity);
      $this->eventDispatcher->dispatch($event, ReplicatorEvents::replicateEntityEvent($entity->getEntityTypeId()));

      if ($clone instanceof FieldableEntityInterface) {
        /** @var FieldableEntityInterface $clone */
        $this->dispatchEventCloneEntityFields($clone);
      }

      $event = new ReplicateAlterEvent($clone, $entity);
      $this->eventDispatcher->dispatch($event, ReplicatorEvents::REPLICATE_ALTER);
      return $clone;
    }
  }

The rough summary is:

  1. Create a duplicate of the passed in entity: A, let's call it B
  2. Fire an event to say that A is being replicated
  3. Fire an event to say that the fields on B are being replicated
  4. Fire another event to say that A is being replicated to B

But note how the second step passes in A and not B, so anyone implementing this event ends up frustrated because they can't do much. The only thing I could think that you could do is throw an exception?
I don't think that's the intended use-case here, and humbly suggest this is a bug.

Steps to reproduce

Replicate an entity.

Proposed resolution

Fix the bug.

Remaining tasks

Write a patch, test it.

User interface changes

None.

API changes

The replicated entity will be passed to the event.

Data model changes

None.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Steven Jones

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024