EntityTypeEvent example

    // iterating handlers is possible: https://www.drupal.org/node/2332857.     $storage = $this->entityTypeManager->getStorage($entity_type_id);
    if ($storage instanceof EntityTypeListenerInterface) {
      $storage->onEntityTypeCreate($entity_type);
    }

    $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id$this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
    }

    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
    $this->clearCachedDefinitions();
  }

  /** * {@inheritdoc} */
  public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
    $entity_type_id = $entity_type->id();

    // @todo Forward this to all interested handlers, not only storage, once     // iterating handlers is possible: https://www.drupal.org/node/2332857.
// Make the test entity type revisionable.     $this->updateEntityTypeToRevisionable(TRUE);

    $views = $entity_storage->loadMultiple();

    // Ensure that all test views exists.     $this->assertTrue(isset($views['test_view_entity_test']));
    $this->assertTrue(isset($views['test_view_entity_test_revision']));
    $this->assertTrue(isset($views['test_view_entity_test_data']));
    $this->assertTrue(isset($views['test_view_entity_test_additional_base_field']));

    $event = new EntityTypeEvent($this->entityTypeManager->getDefinition('entity_test_update'));
    $this->eventDispatcher->dispatch($event, EntityTypeEvents::DELETE);

    // We expect that views which use 'entity_test_update' as base tables are     // disabled.     $views = $entity_storage->loadMultiple();

    // Ensure that all test views still exists after the deletion of the     // entity type.     $this->assertTrue(isset($views['test_view_entity_test']));
    $this->assertTrue(isset($views['test_view_entity_test_revision']));
    $this->assertTrue(isset($views['test_view_entity_test_data']));
    
Home | Imprint | This part of the site doesn't use cookies.