function EntityDefinitionTestTrait::applyEntityUpdates

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::applyEntityUpdates()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::applyEntityUpdates()
  3. 11.x core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::applyEntityUpdates()

Applies all the detected valid changes.

Use this with care, as it will apply updates for any module, which will lead to unpredictable results.

Parameters

string $entity_type_id: (optional) Applies changes only for the specified entity type ID. Defaults to NULL.

21 calls to EntityDefinitionTestTrait::applyEntityUpdates()
ContentEntityNonRevisionableFieldTest::testMultiColumnNonRevisionableBaseField in core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNonRevisionableFieldTest.php
Tests multi column non revisionable base field for revisionable entity.
DefaultTableMappingIntegrationTest::setUp in core/tests/Drupal/KernelTests/Core/Entity/DefaultTableMappingIntegrationTest.php
EntityDefinitionTestTrait::enableNewEntityType in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Enables a new entity type definition.
EntityDefinitionUpdateProviderTest::testBaseFieldDeleteWithExistingData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateProviderTest.php
Tests deleting a base field when it has existing data.
EntityDefinitionUpdateTest::testBaseFieldCreateDeleteWithExistingEntities in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests creating and deleting a base field if entities exist.

... See full list

File

core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php, line 27

Class

EntityDefinitionTestTrait
Provides some test methods used to update existing entity definitions.

Namespace

Drupal\Tests\system\Functional\Entity\Traits

Code

protected function applyEntityUpdates($entity_type_id = NULL) {
    $complete_change_list = \Drupal::entityDefinitionUpdateManager()->getChangeList();
    if ($complete_change_list) {
        // In case there are changes, explicitly invalidate caches.
        \Drupal::entityTypeManager()->clearCachedDefinitions();
        \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    }
    if ($entity_type_id) {
        $complete_change_list = array_intersect_key($complete_change_list, [
            $entity_type_id => TRUE,
        ]);
    }
    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 = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
            $original_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);
            foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
                $storage_definition = $storage_definitions[$field_name] ?? NULL;
                $original_storage_definition = $original_storage_definitions[$field_name] ?? NULL;
                $this->doFieldUpdate($change, $storage_definition, $original_storage_definition);
            }
        }
    }
}

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