You are here

protected function EntityDefinitionUpdateManager::getChangeList in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php \Drupal\Core\Entity\EntityDefinitionUpdateManager::getChangeList()

Gets a list of changes to entity type and field storage definitions.

Return value

array An associative array keyed by entity type id of change descriptors. Every entry is an associative array with the following optional keys:

  • entity_type: a scalar having only the DEFINITION_UPDATED value.
  • field_storage_definitions: an associative array keyed by field name of scalars having one value among:

    • DEFINITION_CREATED
    • DEFINITION_UPDATED
    • DEFINITION_DELETED
3 calls to EntityDefinitionUpdateManager::getChangeList()
EntityDefinitionUpdateManager::applyUpdates in core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php
Applies all the detected valid changes.
EntityDefinitionUpdateManager::getChangeSummary in core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php
Gets a human readable summary of the detected changes.
EntityDefinitionUpdateManager::needsUpdates in core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php
Checks if there are any definition updates that need to be applied.

File

core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php, line 266
Contains \Drupal\Core\Entity\EntityDefinitionUpdateManager.

Class

EntityDefinitionUpdateManager
Manages entity definition updates.

Namespace

Drupal\Core\Entity

Code

protected function getChangeList() {
  $this->entityManager
    ->useCaches(FALSE);
  $change_list = array();
  foreach ($this->entityManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $original = $this->entityManager
      ->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->entityManager
        ->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) {
        $field_changes = array();
        $storage_definitions = $this->entityManager
          ->getFieldStorageDefinitions($entity_type_id);
        $original_storage_definitions = $this->entityManager
          ->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/2282119.
  $this->entityManager
    ->useCaches(TRUE);
  return array_filter($change_list);
}