public function BundlePluginInstaller::uninstallBundles in Entity API 8
Uninstalls the bundle plugins provided by the specified modules.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
array $modules: The modules.
Overrides BundlePluginInstallerInterface::uninstallBundles
File
- src/
BundlePlugin/ BundlePluginInstaller.php, line 80
Class
Namespace
Drupal\entity\BundlePluginCode
public function uninstallBundles(EntityTypeInterface $entity_type, array $modules) {
$bundle_handler = $this->entityTypeManager
->getHandler($entity_type
->id(), 'bundle_plugin');
$bundles = array_filter($bundle_handler
->getBundleInfo(), function ($bundle_info) use ($modules) {
return in_array($bundle_info['provider'], $modules, TRUE);
});
/**
* We need to uninstall the field storage definitions in a separate loop.
*
* This way we can allow a module to re-use the same field within multiple
* bundles, allowing e.g to subclass a bundle plugin.
*
* @var \Drupal\entity\BundleFieldDefinition[] $field_storage_definitions
*/
$field_storage_definitions = [];
foreach (array_keys($bundles) as $bundle) {
$this->entityBundleListener
->onBundleDelete($bundle, $entity_type
->id());
foreach ($bundle_handler
->getFieldDefinitions($bundle) as $definition) {
$this->fieldDefinitionListener
->onFieldDefinitionDelete($definition);
$field_storage_definitions[$definition
->getName()] = $definition;
}
}
foreach ($field_storage_definitions as $definition) {
$this->fieldStorageDefinitionListener
->onFieldStorageDefinitionDelete($definition);
}
}