onBundleDelete example

$this->entityFieldManager->clearCachedFieldDefinitions();
  }

  /** * {@inheritdoc} */
  public function onBundleDelete($bundle$entity_type_id) {
    $this->entityTypeBundleInfo->clearCachedBundles();
    // Notify the entity storage.     $storage = $this->entityTypeManager->getStorage($entity_type_id);
    if ($storage instanceof EntityBundleListenerInterface) {
      $storage->onBundleDelete($bundle$entity_type_id);
    }
    // Invoke hook_entity_bundle_delete() hook.     $this->moduleHandler->invokeAll('entity_bundle_delete', [$entity_type_id$bundle]);
    $this->entityFieldManager->clearCachedFieldDefinitions();
  }

}
    // necessarily installed.     foreach ($module_list as $module) {

      // Clean up all entity bundles (including fields) of every entity type       // provided by the module that is being uninstalled.       // @todo Clean this up in https://www.drupal.org/node/2350111.       $entity_type_manager = \Drupal::entityTypeManager();
      $entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
      foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
        if ($entity_type->getProvider() == $module) {
          foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) {
            \Drupal::service('entity_bundle.listener')->onBundleDelete($bundle$entity_type_id);
          }
        }
      }

      // Allow modules to react prior to the uninstallation of a module.       $this->moduleHandler->invokeAll('module_preuninstall', [$module]);

      // Uninstall the module.       $this->moduleHandler->loadInclude($module, 'install');
      $this->moduleHandler->invoke($module, 'uninstall', [$sync_status]);

      

  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);

    foreach ($entities as $entity) {
      $entity->deleteDisplays();
      \Drupal::service('entity_bundle.listener')->onBundleDelete($entity->id()$entity->getEntityType()->getBundleOf());
    }
  }

  /** * Acts on an entity before the presave hook is invoked. * * Used before the entity is saved and before invoking the presave hook. * * Ensure that config entities which are bundles of other entities cannot have * their ID changed. * * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage object. * * @throws \Drupal\Core\Config\ConfigNameException * Thrown when attempting to rename a bundle entity. */
Home | Imprint | This part of the site doesn't use cookies.