You are here

public function EntityDefinitionUpdateManager::getChangeSummary in Zircon Profile 8

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

Gets a human readable summary of the detected changes.

Return value

array An associative array keyed by entity type id. Each entry is an array of human-readable strings, each describing a change.

Overrides EntityDefinitionUpdateManagerInterface::getChangeSummary

File

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

Class

EntityDefinitionUpdateManager
Manages entity definition updates.

Namespace

Drupal\Core\Entity

Code

public function getChangeSummary() {
  $summary = array();
  foreach ($this
    ->getChangeList() as $entity_type_id => $change_list) {

    // Process entity type definition changes.
    if (!empty($change_list['entity_type'])) {
      $entity_type = $this->entityManager
        ->getDefinition($entity_type_id);
      $t_args = array(
        '%entity_type' => $entity_type
          ->getLabel(),
      );
      switch ($change_list['entity_type']) {
        case static::DEFINITION_CREATED:
          $summary[$entity_type_id][] = $this
            ->t('Create the %entity_type entity type.', $t_args);
          break;
        case static::DEFINITION_UPDATED:
          $summary[$entity_type_id][] = $this
            ->t('Update the %entity_type entity type.', $t_args);
          break;
      }
    }

    // Process field storage definition changes.
    if (!empty($change_list['field_storage_definitions'])) {
      $storage_definitions = $this->entityManager
        ->getFieldStorageDefinitions($entity_type_id);
      $original_storage_definitions = $this->entityManager
        ->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('Create the %field_name field.', array(
              '%field_name' => $storage_definitions[$field_name]
                ->getLabel(),
            ));
            break;
          case static::DEFINITION_UPDATED:
            $summary[$entity_type_id][] = $this
              ->t('Update the %field_name field.', array(
              '%field_name' => $storage_definitions[$field_name]
                ->getLabel(),
            ));
            break;
          case static::DEFINITION_DELETED:
            $summary[$entity_type_id][] = $this
              ->t('Delete the %field_name field.', array(
              '%field_name' => $original_storage_definitions[$field_name]
                ->getLabel(),
            ));
            break;
        }
      }
    }
  }
  return $summary;
}