12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- use Drupal\Core\Entity\EntityTypeInterface;
- use Drupal\entity\BundlePlugin\BundlePluginHandler;
- function entity_get_bundle_plugin_entity_types() {
- $entity_types = \Drupal::entityTypeManager()->getDefinitions();
- $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
- return $entity_type->hasHandlerClass('bundle_plugin');
- });
- return $entity_types;
- }
- function entity_entity_type_build(array &$entity_types) {
- foreach ($entity_types as $entity_type) {
- if ($entity_type->get('bundle_plugin_type')) {
- $entity_type->setHandlerClass('bundle_plugin', BundlePluginHandler::class);
- }
- }
- }
- function entity_entity_bundle_info() {
- $bundles = [];
- foreach (entity_get_bundle_plugin_entity_types() as $entity_type) {
-
- $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin');
- $bundles[$entity_type->id()] = $bundle_handler->getBundleInfo();
- }
- return $bundles;
- }
- function entity_entity_field_storage_info(EntityTypeInterface $entity_type) {
- if ($entity_type->hasHandlerClass('bundle_plugin')) {
-
- $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin');
- return $bundle_handler->getFieldStorageDefinitions();
- }
- }
- function entity_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle) {
- if ($entity_type->hasHandlerClass('bundle_plugin')) {
-
- $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin');
- return $bundle_handler->getFieldDefinitions($bundle);
- }
- }
- function entity_modules_installed($modules) {
- foreach (entity_get_bundle_plugin_entity_types() as $entity_type) {
- \Drupal::service('entity.bundle_plugin_installer')->installBundles($entity_type, $modules);
- }
- }
- function entity_module_preuninstall($module) {
- foreach (entity_get_bundle_plugin_entity_types() as $entity_type) {
- \Drupal::service('entity.bundle_plugin_installer')->uninstallBundles($entity_type, [$module]);
- }
- }
|