EntityBundleListener.php in Drupal 8
File
core/lib/Drupal/Core/Entity/EntityBundleListener.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Extension\ModuleHandlerInterface;
class EntityBundleListener implements EntityBundleListenerInterface {
protected $entityTypeManager;
protected $entityTypeBundleInfo;
protected $entityFieldManager;
protected $moduleHandler;
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->entityFieldManager = $entity_field_manager;
$this->moduleHandler = $module_handler;
}
public function onBundleCreate($bundle, $entity_type_id) {
$this->entityTypeBundleInfo
->clearCachedBundles();
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
if ($storage instanceof EntityBundleListenerInterface) {
$storage
->onBundleCreate($bundle, $entity_type_id);
}
$this->moduleHandler
->invokeAll('entity_bundle_create', [
$entity_type_id,
$bundle,
]);
$this->entityFieldManager
->clearCachedFieldDefinitions();
}
public function onBundleDelete($bundle, $entity_type_id) {
$this->entityTypeBundleInfo
->clearCachedBundles();
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
if ($storage instanceof EntityBundleListenerInterface) {
$storage
->onBundleDelete($bundle, $entity_type_id);
}
$this->moduleHandler
->invokeAll('entity_bundle_delete', [
$entity_type_id,
$bundle,
]);
$this->entityFieldManager
->clearCachedFieldDefinitions();
}
}