You are here

public function BundlePluginInstaller::installBundles in Entity API 8

Installs the bundle plugins provided by the specified modules.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

array $modules: The modules.

Overrides BundlePluginInstallerInterface::installBundles

File

src/BundlePlugin/BundlePluginInstaller.php, line 63

Class

BundlePluginInstaller

Namespace

Drupal\entity\BundlePlugin

Code

public function installBundles(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);
  });
  foreach (array_keys($bundles) as $bundle) {
    $this->entityBundleListener
      ->onBundleCreate($bundle, $entity_type
      ->id());
    foreach ($bundle_handler
      ->getFieldDefinitions($bundle) as $definition) {
      $this->fieldStorageDefinitionListener
        ->onFieldStorageDefinitionCreate($definition);
      $this->fieldDefinitionListener
        ->onFieldDefinitionCreate($definition);
    }
  }
}