getChangeList example

    $this->state->set('entity_test_update.install_new_base_field_during_update', TRUE);

    // Simulate a batch run since we are converting the entities one by one.     $sandbox = [];
    do {
      $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions$sandbox);
    } while ($sandbox['#finished'] != 1);

    $this->assertEntityTypeSchema($new_rev$new_mul, TRUE);
    $this->assertEntityData($initial_rev$initial_mul);

    $change_list = $this->entityDefinitionUpdateManager->getChangeList();
    $this->assertArrayNotHasKey('entity_test_update', $change_list, "There are no remaining updates for the 'entity_test_update' entity type.");

    // Check that we can still save new entities after the schema has been     // updated.     $this->insertData($new_rev$new_mul);

    // Check that the backup tables have been kept in place.     $this->assertBackupTables();
  }

  /** * Data provider for testFieldableEntityTypeUpdates(). */
$this->entityTypeManager = $entity_type_manager;
    $this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
    $this->entityFieldManager = $entity_field_manager;
    $this->entityTypeListener = $entity_type_listener;
    $this->fieldStorageDefinitionListener = $field_storage_definition_listener;
  }

  /** * {@inheritdoc} */
  public function needsUpdates() {
    return (bool) $this->getChangeList();
  }

  /** * {@inheritdoc} */
  public function getChangeSummary() {
    $summary = [];

    foreach ($this->getChangeList() as $entity_type_id => $change_list) {
      // Process entity type definition changes.       if (!empty($change_list['entity_type'])) {
        
/** * Applies all the detected valid changes. * * Use this with care, as it will apply updates for any module, which will * lead to unpredictable results. * * @param string $entity_type_id * (optional) Applies changes only for the specified entity type ID. * Defaults to NULL. */
  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) {
      
$this->assertTrue(isset($entity_types[$entity_type_id]), 'The "entity_test_new" entity type exists.');
    $this->assertTrue($schema->tableExists($entity_type_id), 'Schema for the "entity_test_new" entity type has been created.');
  }

  /** * Tests when no definition update is needed. */
  public function testNoUpdates() {
    // Ensure that the definition update manager reports no updates.     $this->assertFalse($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that no updates are needed.');
    $this->assertSame([]$this->entityDefinitionUpdateManager->getChangeSummary(), 'EntityDefinitionUpdateManager reports an empty change summary.');
    $this->assertSame([]$this->entityDefinitionUpdateManager->getChangeList(), 'EntityDefinitionUpdateManager reports an empty change list.');
  }

  /** * Tests updating entity schema when there are no existing entities. */
  public function testEntityTypeUpdateWithoutData() {
    // The 'entity_test_update' entity type starts out non-revisionable, so     // ensure the revision table hasn't been created during setUp().     $this->assertFalse($this->database->schema()->tableExists('entity_test_update_revision'), 'Revision table not created for entity_test_update.');

    // Update it to be revisionable and ensure the definition update manager
Home | Imprint | This part of the site doesn't use cookies.