getUpdatedEntityTypeDefinition example


  protected function enableNewEntityType() {
    $this->state->set('entity_test_new', TRUE);
    $this->applyEntityUpdates('entity_test_new');
  }

  /** * Resets the entity type definition. */
  protected function resetEntityType() {
    $updated_entity_type = $this->getUpdatedEntityTypeDefinition(FALSE, FALSE);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(FALSE, FALSE);
    $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions);
  }

  /** * Updates the 'entity_test_update' entity type to revisionable. * * @param bool $perform_update * (optional) Whether the change should be performed by the entity * definition update manager. */
  
// Run the update and ensure the revision table is created.     $this->updateEntityTypeToRevisionable(TRUE);
    $this->assertTrue($this->database->schema()->tableExists('entity_test_update_revision'), 'Revision table created for entity_test_update.');
  }

  /** * Tests updating entity schema when there are entity storage changes. */
  public function testEntityTypeUpdateWithEntityStorageChange() {
    // Update the entity type to be revisionable and try to apply the update.     // It's expected to throw an exception.     $entity_type = $this->getUpdatedEntityTypeDefinition(TRUE, FALSE);
    try {
      $this->entityDefinitionUpdateManager->updateEntityType($entity_type);
      $this->fail('EntityStorageException thrown when trying to apply an update that requires shared table schema changes.');
    }
    catch (EntityStorageException $e) {
      // Expected exception; just continue testing.     }
  }

  /** * Tests installing an additional base field while installing an entity type. * * @covers ::installFieldableEntityType */
/** * @covers ::updateFieldableEntityType * @dataProvider providerTestFieldableEntityTypeUpdates */
  public function testFieldableEntityTypeUpdates($initial_rev$initial_mul$new_rev$new_mul$data_migration_supported) {
    // The 'entity_test_update' entity type is neither revisionable nor     // translatable by default, so we need to get it into the initial testing     // state. This also covers the "no existing data" scenario for fieldable     // entity type updates.     if ($initial_rev || $initial_mul) {
      $entity_type = $this->getUpdatedEntityTypeDefinition($initial_rev$initial_mul);
      $field_storage_definitions = $this->getUpdatedFieldStorageDefinitions($initial_rev$initial_mul);

      $this->entityDefinitionUpdateManager->updateFieldableEntityType($entity_type$field_storage_definitions);
      $this->assertEntityTypeSchema($initial_rev$initial_mul);
    }

    // Add a few entities so we can test the data copying step.     $this->insertData($initial_rev$initial_mul);

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition($new_rev$new_mul);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions($new_rev$new_mul);

    
$this->assertFalse($this->database->schema()->tableExists($table), 'Table dropped');
  }

  /** * Updates the entity type definition. * * @param bool $alter * Whether the original definition should be altered or not. */
  protected function updateEntityType($alter) {
    $this->state->set('entity_schema_update', $alter);
    $updated_entity_type = $this->getUpdatedEntityTypeDefinition($alter$alter);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions($alter$alter);
    $this->container->get('entity.definition_update_manager')->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions);
  }

  /** * Tests that entity schema responds to changes in the entity type definition. */
  public function testEntitySchemaUpdate() {
    $this->installModule('entity_schema_test');
    $storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
    
Home | Imprint | This part of the site doesn't use cookies.