class MyEntityCloneEventSubscriber in Entity Clone 8
Event subscribers for Entity Clone.
Service definition for my_module.services.yml: <code> ```yaml my_module.my_event_subscriber: class: Drupal\my_module\EventSubscriber\MyEntityCloneEventSubscriber tags:
- { name: event_subscriber }
``` </code>
Code for src/EventSubscriber/MyEntityCloneEventSubscriber.php <code> <?php namespace Drupal\my_module\EventSubscriber; ?> </code>
Hierarchy
- class \MyEntityCloneEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MyEntityCloneEventSubscriber
File
- ./
entity_clone.api.php, line 28 - Entity Clone hooks and events.
View source
class MyEntityCloneEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface {
/**
* An example event subscriber.
*
* Dispatched before an entity is cloned and saved.
*
* @see \Drupal\entity_clone\Event\EntityCloneEvents::PRE_CLONE
*/
public function myPreClone(\Drupal\entity_clone\Event\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(\Drupal\entity_clone\Event\EntityCloneEvent $event) : void {
$original = $event
->getEntity();
$newEntity = $event
->getClonedEntity();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[\Drupal\entity_clone\Event\EntityCloneEvents::PRE_CLONE][] = [
'myPreClone',
];
$events[\Drupal\entity_clone\Event\EntityCloneEvents::POST_CLONE][] = [
'myPostClone',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MyEntityCloneEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
MyEntityCloneEventSubscriber:: |
public | function | An example event subscriber. | |
MyEntityCloneEventSubscriber:: |
public | function | An example event subscriber. |