You are here

protected function BundlePluginInstaller::getFieldDefinitionsToPersist in farmOS 2.x

Get field definitions from all remaining bundles.

Parameters

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

array $uninstalled_bundles: The bundles that will be uninstalled.

Return value

array Remaining field definitions.

1 call to BundlePluginInstaller::getFieldDefinitionsToPersist()
BundlePluginInstaller::uninstallBundles in modules/core/entity/src/BundlePlugin/BundlePluginInstaller.php

File

modules/core/entity/src/BundlePlugin/BundlePluginInstaller.php, line 69

Class

BundlePluginInstaller
Extends the entity BundlePluginInstaller service.

Namespace

Drupal\farm_entity\BundlePlugin

Code

protected function getFieldDefinitionsToPersist(EntityTypeInterface $entity_type, array $uninstalled_bundles) {
  $bundle_handler = $this->entityTypeManager
    ->getHandler($entity_type
    ->id(), 'bundle_plugin');
  $remaining_bundles = array_filter($bundle_handler
    ->getBundleInfo(), function ($bundle_name) use ($uninstalled_bundles) {
    return !in_array($bundle_name, $uninstalled_bundles, TRUE);
  }, ARRAY_FILTER_USE_KEY);
  $fields_to_persist = [];
  foreach (array_keys($remaining_bundles) as $bundle) {
    foreach ($bundle_handler
      ->getFieldDefinitions($bundle) as $definition) {
      $field_name = $definition
        ->getName();
      if (!isset($fields_to_persist[$field_name])) {
        $fields_to_persist[$field_name] = $definition;
      }
    }
  }
  return $fields_to_persist;
}