You are here

public function EntityLastInstalledSchemaRepository::getLastInstalledDefinitions in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()
  2. 9 core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()

File

core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php, line 59

Class

EntityLastInstalledSchemaRepository
Provides a repository for installed entity definitions.

Namespace

Drupal\Core\Entity

Code

public function getLastInstalledDefinitions() {
  if ($this->entityTypeDefinitions) {
    return $this->entityTypeDefinitions;
  }
  elseif ($cache = $this->cacheBackend
    ->get('entity_type_definitions.installed')) {
    $this->entityTypeDefinitions = $cache->data;
    return $this->entityTypeDefinitions;
  }
  $all_definitions = $this->keyValueFactory
    ->get('entity.definitions.installed')
    ->getAll();

  // Filter out field storage definitions.
  $filtered_keys = array_filter(array_keys($all_definitions), function ($key) {
    return substr($key, -12) === '.entity_type';
  });
  $entity_type_definitions = array_intersect_key($all_definitions, array_flip($filtered_keys));

  // Ensure that the returned array is keyed by the entity type ID.
  $keys = array_keys($entity_type_definitions);
  $keys = array_map(function ($key) {
    $parts = explode('.', $key);
    return $parts[0];
  }, $keys);
  $this->entityTypeDefinitions = array_combine($keys, $entity_type_definitions);
  $this->cacheBackend
    ->set('entity_type_definitions.installed', $this->entityTypeDefinitions, Cache::PERMANENT);
  return $this->entityTypeDefinitions;
}