diff --git a/src/Entity/EckEntityType.php b/src/Entity/EckEntityType.php index dc4929b..da363b2 100644 --- a/src/Entity/EckEntityType.php +++ b/src/Entity/EckEntityType.php @@ -110,6 +110,15 @@ class EckEntityType extends ConfigEntityBase implements EckEntityTypeInterface { } /** + * {@inheritdoc} + */ + public function delete() { + parent::delete(); + $this->logger($this->id())->info('Entity type %label has been deleted.', ['%label' => $this->label()]); + $this->entityTypeManager()->clearCachedDefinitions(); + } + + /** * Gets the logger for a specific channel. * * @param string $channel diff --git a/tests/src/Kernel/EckEntityTypeTest.php b/tests/src/Kernel/EckEntityTypeTest.php new file mode 100644 index 0000000..2e09bcb --- /dev/null +++ b/tests/src/Kernel/EckEntityTypeTest.php @@ -0,0 +1,55 @@ +entityTypeManager = \Drupal::entityTypeManager(); + } + + /** + * @test + */ + public function newlyCreatedEntitiesArePickedUpByEntityTypeManager() { + $this->assertFalse((bool) $this->entityTypeManager->getDefinition('test_entity_type', FALSE)); + + $this->createEntityType('test_entity_type', 'Test entity type'); + + $this->assertTrue((bool) $this->entityTypeManager->getDefinition('test_entity_type', FALSE)); + } + + /** + * @test + */ + public function deletingAnEntityTypeIsPickedUpByEntityTypeManager() { + $this->createEntityType('test_entity_type', 'Test entity type'); + + $entityType = $this->entityTypeManager->getStorage('eck_entity_type')->load('test_entity_type'); + $entityType->delete(); + + $this->assertFalse((bool) $this->entityTypeManager->getDefinition('test_entity_type', FALSE)); + } + + /** + * @param string $machineName + * @param string $label + */ + public function createEntityType($machineName, $label) { + $entityStorage = $this->entityTypeManager->getStorage('eck_entity_type'); + $values = ['id' => $machineName, 'label' => $label]; + + $entityStorage->create($values)->save(); + } + +}