Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityBundleListener.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6
7 /**
8  * Reacts to entity bundle CRUD on behalf of the Entity system.
9  */
10 class EntityBundleListener implements EntityBundleListenerInterface {
11
12   /**
13    * The entity type manager.
14    *
15    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
16    */
17   protected $entityTypeManager;
18
19   /**
20    * The entity type bundle info.
21    *
22    * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
23    */
24   protected $entityTypeBundleInfo;
25
26   /**
27    * The entity field manager.
28    *
29    * @var \Drupal\Core\Entity\EntityFieldManagerInterface
30    */
31   protected $entityFieldManager;
32
33   /**
34    * The module handler.
35    *
36    * @var \Drupal\Core\Extension\ModuleHandlerInterface
37    */
38   protected $moduleHandler;
39
40   /**
41    * Constructs a new EntityBundleListener.
42    *
43    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
44    *   The entity type manager.
45    * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
46    *   The entity type bundle info.
47    * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
48    *   The entity field manager.
49    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
50    *   The module handler.
51    */
52   public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, ModuleHandlerInterface $module_handler) {
53     $this->entityTypeManager = $entity_type_manager;
54     $this->entityTypeBundleInfo = $entity_type_bundle_info;
55     $this->entityFieldManager = $entity_field_manager;
56     $this->moduleHandler = $module_handler;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function onBundleCreate($bundle, $entity_type_id) {
63     $this->entityTypeBundleInfo->clearCachedBundles();
64     // Notify the entity storage.
65     $storage = $this->entityTypeManager->getStorage($entity_type_id);
66     if ($storage instanceof EntityBundleListenerInterface) {
67       $storage->onBundleCreate($bundle, $entity_type_id);
68     }
69     // Invoke hook_entity_bundle_create() hook.
70     $this->moduleHandler->invokeAll('entity_bundle_create', [$entity_type_id, $bundle]);
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   public function onBundleDelete($bundle, $entity_type_id) {
77     $this->entityTypeBundleInfo->clearCachedBundles();
78     // Notify the entity storage.
79     $storage = $this->entityTypeManager->getStorage($entity_type_id);
80     if ($storage instanceof EntityBundleListenerInterface) {
81       $storage->onBundleDelete($bundle, $entity_type_id);
82     }
83     // Invoke hook_entity_bundle_delete() hook.
84     $this->moduleHandler->invokeAll('entity_bundle_delete', [$entity_type_id, $bundle]);
85     $this->entityFieldManager->clearCachedFieldDefinitions();
86   }
87
88 }