function EntityLastInstalledSchemaRepository::getLastInstalledDefinitions
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()
- 10 core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()
- 9 core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()
- 8.9.x core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php \Drupal\Core\Entity\EntityLastInstalledSchemaRepository::getLastInstalledDefinitions()
Gets the entity type definitions in their most recently installed state.
During the application lifetime, entity type definitions can change. For example, updated code can be deployed. The \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinitions() method will always return the definitions as determined by the current codebase. This method returns the definitions from the last time that a \Drupal\Core\Entity\EntityTypeListener event was completed. In other words, the definitions that the entity type's handlers have incorporated into the application state. For example, if the entity type's storage handler is SQL-based, the definition for which database tables were created.
Application management code can check if \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinitions() differs from getLastInstalledDefinitions() and decide whether to:
- Invoke the appropriate \Drupal\Core\Entity\EntityTypeListenerInterface event so that handlers react to the new definitions.
- Raise a warning that the application state is incompatible with the codebase.
- Perform some other action.
Return value
\Drupal\Core\Entity\EntityTypeInterface[] An array containing the installed definition for all entity types, keyed by the entity type ID.
Overrides EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinitions
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityLastInstalledSchemaRepository.php, line 66
Class
- EntityLastInstalledSchemaRepository
- Provides a repository for installed entity definitions.
Namespace
Drupal\Core\EntityCode
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 str_ends_with($key, '.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);
// Also populate the static and persistent cache for the field storage
// definitions to avoid a separate key/value lookup when all definitions are
// looked up first.
$items = [
'entity_type_definitions.installed' => [
'data' => $this->entityTypeDefinitions,
'expires' => Cache::PERMANENT,
],
];
foreach ($keys as $key) {
$this->entityFieldStorageDefinitions[$key] = $all_definitions[$key . '.field_storage_definitions'] ?? [];
$items[$key . '.field_storage_definitions.installed'] = [
'data' => $this->entityFieldStorageDefinitions[$key],
'expires' => Cache::PERMANENT,
];
}
$this->cacheBackend
->setMultiple($items);
return $this->entityTypeDefinitions;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.