class EntityDuplicateSubscriber in Entity API 8
Hierarchy
- class \Drupal\entity\EventSubscriber\EntityDuplicateSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of EntityDuplicateSubscriber
1 string reference to 'EntityDuplicateSubscriber'
1 service uses EntityDuplicateSubscriber
File
- src/
EventSubscriber/ EntityDuplicateSubscriber.php, line 10
Namespace
Drupal\entity\EventSubscriberView source
class EntityDuplicateSubscriber implements EventSubscriberInterface {
/**
* The bundle entity duplicator.
*
* @var \Drupal\entity\BundleEntityDuplicatorInterface
*/
protected $bundleEntityDuplicator;
/**
* Constructs a new EntityDuplicateSubscriber object.
*
* @param \Drupal\entity\BundleEntityDuplicatorInterface $bundle_entity_duplicator
* The bundle entity duplicator.
*/
public function __construct(BundleEntityDuplicatorInterface $bundle_entity_duplicator) {
$this->bundleEntityDuplicator = $bundle_entity_duplicator;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [
EntityEvents::ENTITY_DUPLICATE => [
'onEntityDuplicate',
],
];
return $events;
}
/**
* Duplicates bundle fields and displays.
*
* @param \Drupal\entity\Event\EntityDuplicateEvent $event
* The entity duplicate event.
*/
public function onEntityDuplicate(EntityDuplicateEvent $event) {
$entity = $event
->getEntity();
if ($entity
->getEntityType()
->getBundleOf()) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $source_entity */
$source_entity = $event
->getSourceEntity();
$this->bundleEntityDuplicator
->duplicateFields($source_entity, $entity
->id());
$this->bundleEntityDuplicator
->duplicateDisplays($source_entity, $entity
->id());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityDuplicateSubscriber:: |
protected | property | The bundle entity duplicator. | |
EntityDuplicateSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
EntityDuplicateSubscriber:: |
public | function | Duplicates bundle fields and displays. | |
EntityDuplicateSubscriber:: |
public | function | Constructs a new EntityDuplicateSubscriber object. |