uninstallEntityType example

\Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));

      // Notify interested components that this module's entity types are being       // deleted. For example, a SQL-based storage handler can use this as an       // opportunity to drop the corresponding database tables.       // @todo Clean this up in https://www.drupal.org/node/2350111.       $update_manager = \Drupal::entityDefinitionUpdateManager();
      /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
      $entity_field_manager = \Drupal::service('entity_field.manager');
      foreach ($entity_type_manager->getDefinitions() as $entity_type) {
        if ($entity_type->getProvider() == $module) {
          $update_manager->uninstallEntityType($entity_type);
        }
        elseif ($entity_type->entityClassImplements(FieldableEntityInterface::CLASS)) {
          // The module being uninstalled might have added new fields to           // existing entity types. This will add them to the deleted fields           // repository so their data will be purged on cron.           foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
            if ($storage_definition->getProvider() == $module) {
              $update_manager->uninstallFieldStorageDefinition($storage_definition);
            }
          }
        }
      }

  public function testUninstallEntityTypeWithoutInCodeDefinition() {
    $entity_type = clone $this->entityTypeManager->getDefinition('entity_test_update');

    // Remove the entity type definition. This is the same thing as removing the     // code that defines it.     $this->deleteEntityType();

    // Now uninstall it and check that the tables have been removed.     $this->assertTrue($this->database->schema()->tableExists('entity_test_update'), 'Base table for entity_test_update exists before uninstalling it.');
    $this->entityDefinitionUpdateManager->uninstallEntityType($entity_type);
    $this->assertFalse($this->database->schema()->tableExists('entity_test_update'), 'Base table for entity_test_update does not exist anymore.');
  }

  /** * Tests uninstalling a revisionable entity type that doesn't exist in code. * * @covers ::uninstallEntityType */
  public function testUninstallRevisionableEntityTypeWithoutInCodeDefinition() {
    $this->updateEntityTypeToRevisionable(TRUE);
    $entity_type = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update');

    
Home | Imprint | This part of the site doesn't use cookies.