function EntityDefinitionUpdateManager::getChangeList

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php \Drupal\Core\Entity\EntityDefinitionUpdateManager::getChangeList()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php \Drupal\Core\Entity\EntityDefinitionUpdateManager::getChangeList()
  3. 11.x core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php \Drupal\Core\Entity\EntityDefinitionUpdateManager::getChangeList()
2 calls to EntityDefinitionUpdateManager::getChangeList()
EntityDefinitionUpdateManager::getChangeSummary in core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php
EntityDefinitionUpdateManager::needsUpdates in core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php

File

core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php, line 247

Class

EntityDefinitionUpdateManager
Manages entity definition updates.

Namespace

Drupal\Core\Entity

Code

public function getChangeList() {
    $this->entityTypeManager
        ->useCaches(FALSE);
    $this->entityFieldManager
        ->useCaches(FALSE);
    $change_list = [];
    foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type_id => $entity_type) {
        $original = $this->entityLastInstalledSchemaRepository
            ->getLastInstalledDefinition($entity_type_id);
        // @todo Support non-storage-schema-changing definition updates too:
        //   https://www.drupal.org/node/2336895.
        if (!$original) {
            $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_CREATED;
        }
        else {
            if ($this->requiresEntityStorageSchemaChanges($entity_type, $original)) {
                $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED;
            }
            if ($this->entityTypeManager
                ->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) {
                $field_changes = [];
                $storage_definitions = $this->entityFieldManager
                    ->getFieldStorageDefinitions($entity_type_id);
                $original_storage_definitions = $this->entityLastInstalledSchemaRepository
                    ->getLastInstalledFieldStorageDefinitions($entity_type_id);
                // Detect created field storage definitions.
                foreach (array_diff_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) {
                    $field_changes[$field_name] = static::DEFINITION_CREATED;
                }
                // Detect deleted field storage definitions.
                foreach (array_diff_key($original_storage_definitions, $storage_definitions) as $field_name => $original_storage_definition) {
                    $field_changes[$field_name] = static::DEFINITION_DELETED;
                }
                // Detect updated field storage definitions.
                foreach (array_intersect_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) {
                    // @todo Support non-storage-schema-changing definition updates too:
                    //   https://www.drupal.org/node/2336895. So long as we're checking
                    //   based on schema change requirements rather than definition
                    //   equality, skip the check if the entity type itself needs to be
                    //   updated, since that can affect the schema of all fields, so we
                    //   want to process that update first without reporting false
                    //   positives here.
                    if (!isset($change_list[$entity_type_id]['entity_type']) && $this->requiresFieldStorageSchemaChanges($storage_definition, $original_storage_definitions[$field_name])) {
                        $field_changes[$field_name] = static::DEFINITION_UPDATED;
                    }
                }
                if ($field_changes) {
                    $change_list[$entity_type_id]['field_storage_definitions'] = $field_changes;
                }
            }
        }
    }
    // @todo Support deleting entity definitions when we support base field
    //   purging.
    // @see https://www.drupal.org/node/2907779
    $this->entityTypeManager
        ->useCaches(TRUE);
    $this->entityFieldManager
        ->useCaches(TRUE);
    return array_filter($change_list);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.