protected function EntityDefinitionTestTrait::applyEntityUpdates in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::applyEntityUpdates()
- 9 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.
18 calls to EntityDefinitionTestTrait::applyEntityUpdates()
- EntityDefinitionTestTrait::enableNewEntityType in core/
modules/ system/ tests/ src/ Functional/ Entity/ Traits/ EntityDefinitionTestTrait.php - Enables a new entity type definition.
- EntityDefinitionUpdateTest::testBaseFieldCreateDeleteWithExistingEntities in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php - Tests creating and deleting a base field if entities exist.
- EntityDefinitionUpdateTest::testBaseFieldCreateUpdateDeleteWithoutData in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php - Tests creating, updating, and deleting a base field if no entities exist.
- EntityDefinitionUpdateTest::testBaseFieldDeleteWithExistingData in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php - Tests deleting a base field when it has existing data.
- EntityDefinitionUpdateTest::testBaseFieldEntityKeyUpdateWithExistingData in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php - Tests updating a base field when it has existing data.
File
- core/
modules/ system/ tests/ src/ Functional/ Entity/ Traits/ EntityDefinitionTestTrait.php, line 25
Class
- EntityDefinitionTestTrait
- Provides some test methods used to update existing entity definitions.
Namespace
Drupal\Tests\system\Functional\Entity\TraitsCode
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);
}
}
}
}