public function DevelEntityDefinitionUpdateManager::applyUpdates in Devel Entity Updates 3.0.x
Same name and namespace in other branches
- 8.2 src/DevelEntityDefinitionUpdateManager.php \Drupal\devel_entity_updates\DevelEntityDefinitionUpdateManager::applyUpdates()
- 8 src/DevelEntityDefinitionUpdateManager.php \Drupal\devel_entity_updates\DevelEntityDefinitionUpdateManager::applyUpdates()
- 3.x src/DevelEntityDefinitionUpdateManager.php \Drupal\devel_entity_updates\DevelEntityDefinitionUpdateManager::applyUpdates()
Applies all the detected valid changes.
File
- src/
DevelEntityDefinitionUpdateManager.php, line 113
Class
- DevelEntityDefinitionUpdateManager
- Development version of the entity definition update manager.
Namespace
Drupal\devel_entity_updatesCode
public function applyUpdates() {
// Ensure this works also on Drupal 8.6 and earlier.
$reflector = new \ReflectionMethod($this->entityDefinitionUpdateManager, 'getChangeList');
$reflector
->setAccessible(TRUE);
$complete_change_list = $reflector
->invoke($this->entityDefinitionUpdateManager);
if ($complete_change_list) {
// EntityDefinitionUpdateManagerInterface::getChangeList() only disables
// the cache and does not invalidate. In case there are changes,
// explicitly invalidate caches.
$this->entityTypeManager
->clearCachedDefinitions();
$this->entityFieldManager
->clearCachedFieldDefinitions();
}
foreach ($complete_change_list as $entity_type_id => $change_list) {
// Process entity type definition changes before storage definitions ones
// this is necessary when you change an entity type from non-revisionable
// to revisionable and at the same time add revisionable fields to the
// entity type.
if (!empty($change_list['entity_type'])) {
$this
->doEntityUpdate($change_list['entity_type'], $entity_type_id);
}
// Process field storage definition changes.
if (!empty($change_list['field_storage_definitions'])) {
$storage_definitions = $this->entityFieldManager
->getFieldStorageDefinitions($entity_type_id);
$original_storage_definitions = $this->entityLastInstalledSchemaRepository
->getLastInstalledFieldStorageDefinitions($entity_type_id);
foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
$storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL;
$original_storage_definition = isset($original_storage_definitions[$field_name]) ? $original_storage_definitions[$field_name] : NULL;
$this
->doFieldUpdate($change, $storage_definition, $original_storage_definition);
}
}
}
}