X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fentity_test%2Fsrc%2FEntityTestDefinitionSubscriber.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fentity_test%2Fsrc%2FEntityTestDefinitionSubscriber.php;h=2b06d80bd6e2d858c06ac5714c56253f58260f8b;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/system/tests/modules/entity_test/src/EntityTestDefinitionSubscriber.php b/web/core/modules/system/tests/modules/entity_test/src/EntityTestDefinitionSubscriber.php new file mode 100644 index 000000000..2b06d80bd --- /dev/null +++ b/web/core/modules/system/tests/modules/entity_test/src/EntityTestDefinitionSubscriber.php @@ -0,0 +1,126 @@ +state = $state; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + return static::getEntityTypeEvents() + static::getFieldStorageDefinitionEvents(); + } + + /** + * {@inheritdoc} + */ + public function onEntityTypeCreate(EntityTypeInterface $entity_type) { + $this->storeEvent(EntityTypeEvents::CREATE); + } + + /** + * {@inheritdoc} + */ + public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) { + $this->storeEvent(EntityTypeEvents::UPDATE); + } + + /** + * {@inheritdoc} + */ + public function onEntityTypeDelete(EntityTypeInterface $entity_type) { + $this->storeEvent(EntityTypeEvents::DELETE); + } + + /** + * {@inheritdoc} + */ + public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) { + $this->storeEvent(FieldStorageDefinitionEvents::CREATE); + } + + /** + * {@inheritdoc} + */ + public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { + $this->storeEvent(FieldStorageDefinitionEvents::UPDATE); + } + + /** + * {@inheritdoc} + */ + public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) { + $this->storeEvent(FieldStorageDefinitionEvents::DELETE); + } + + /** + * Enables event tracking. + */ + public function enableEventTracking() { + $this->trackEvents = TRUE; + } + + /** + * Checks whether an event has been dispatched. + * + * @param string $event_name + * The event name. + * + * @return bool + * TRUE if the event has been dispatched, FALSE otherwise. + */ + public function hasEventFired($event_name) { + return (bool) $this->state->get($event_name); + } + + /** + * Stores the specified event. + * + * @param string $event_name + * The event name. + */ + protected function storeEvent($event_name) { + if ($this->trackEvents) { + $this->state->set($event_name, TRUE); + } + } + +}