Same name in other branches
  1. 8.x-1.x entity_clone.api.php \MyEntityCloneEventSubscriber

Event subscribers for Entity Clone.

Service definition for my_module.services.yml: ```yaml my_module.my_event_subscriber: class: Drupal\my_module\EventSubscriber\MyEntityCloneEventSubscriber tags:

  • { name: event_subscriber }

```

Code for src/EventSubscriber/MyEntityCloneEventSubscriber.php <?php namespace Drupal\my_module\EventSubscriber; ?>

Hierarchy

Expanded class hierarchy of MyEntityCloneEventSubscriber

Fichier

./entity_clone.api.php, line 36

View source
class MyEntityCloneEventSubscriber implements EventSubscriberInterface {
    
    /**
     * An example event subscriber.
     *
     * Dispatched before an entity is cloned and saved.
     *
     * @see \Drupal\entity_clone\Event\EntityCloneEvents::PRE_CLONE
     */
    public function myPreClone(EntityCloneEvent $event) : void {
        $original = $event->getEntity();
        $newEntity = $event->getClonedEntity();
    }
    
    /**
     * An example event subscriber.
     *
     * Dispatched after an entity is cloned and saved.
     *
     * @see \Drupal\entity_clone\Event\EntityCloneEvents::POST_CLONE
     */
    public function myPostClone(EntityCloneEvent $event) : void {
        $original = $event->getEntity();
        $newEntity = $event->getClonedEntity();
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events[EntityCloneEvents::PRE_CLONE][] = [
            'myPreClone',
        ];
        $events[EntityCloneEvents::POST_CLONE][] = [
            'myPostClone',
        ];
        return $events;
    }

}

Members