function EntityDefinitionUpdateManager::getChangeSummary

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

File

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

Class

EntityDefinitionUpdateManager
Manages entity definition updates.

Namespace

Drupal\Core\Entity

Code

public function getChangeSummary() {
    $summary = [];
    foreach ($this->getChangeList() as $entity_type_id => $change_list) {
        // Process entity type definition changes.
        if (!empty($change_list['entity_type'])) {
            $entity_type = $this->entityTypeManager
                ->getDefinition($entity_type_id);
            switch ($change_list['entity_type']) {
                case static::DEFINITION_CREATED:
                    $summary[$entity_type_id][] = $this->t('The %entity_type entity type needs to be installed.', [
                        '%entity_type' => $entity_type->getLabel(),
                    ]);
                    break;
                case static::DEFINITION_UPDATED:
                    $summary[$entity_type_id][] = $this->t('The %entity_type entity type needs to be updated.', [
                        '%entity_type' => $entity_type->getLabel(),
                    ]);
                    break;
            }
        }
        // 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) {
                switch ($change) {
                    case static::DEFINITION_CREATED:
                        $summary[$entity_type_id][] = $this->t('The %field_name field needs to be installed.', [
                            '%field_name' => $storage_definitions[$field_name]->getLabel() ?: $field_name,
                        ]);
                        break;
                    case static::DEFINITION_UPDATED:
                        $summary[$entity_type_id][] = $this->t('The %field_name field needs to be updated.', [
                            '%field_name' => $storage_definitions[$field_name]->getLabel() ?: $field_name,
                        ]);
                        break;
                    case static::DEFINITION_DELETED:
                        $summary[$entity_type_id][] = $this->t('The %field_name field needs to be uninstalled.', [
                            '%field_name' => $original_storage_definitions[$field_name]->getLabel() ?: $field_name,
                        ]);
                        break;
                }
            }
        }
    }
    return $summary;
}

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