updateFieldableEntityType example


  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);

    if (!$data_migration_supported) {
      $this->expectException(EntityStorageException::class);
      
public function testUpdateFieldableEntityTypeWithoutInCodeDefinition() {
    $entity_type = clone $this->entityTypeManager->getDefinition('entity_test_update');
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');

    // Remove the entity type definition. This is the same thing as removing the     // code that defines it.     $this->deleteEntityType();

    // Rename the base table, update the fieldable entity type and check that     // the table has been renamed.     $entity_type->set('base_table', 'entity_test_update_new');
    $this->entityDefinitionUpdateManager->updateFieldableEntityType($entity_type$field_storage_definitions);

    $this->assertTrue($this->database->schema()->tableExists('entity_test_update_new'), 'The base table has been renamed.');
    $this->assertFalse($this->database->schema()->tableExists('entity_test_update'), 'The old base table does not exist anymore.');
  }

  /** * Tests uninstalling an entity type that doesn't exist in code anymore. * * @covers ::uninstallEntityType */
  public function testUninstallEntityTypeWithoutInCodeDefinition() {
    

  public function testNonLangcodeEntityTypeModeration() {
    // Unset the langcode entity key for 'entity_test_rev'.     $entity_type = clone $this->entityTypeManager->getDefinition($this->revEntityTypeId);
    $keys = $entity_type->getKeys();
    unset($keys['langcode']);
    $entity_type->set('entity_keys', $keys);
    \Drupal::state()->set($this->revEntityTypeId . '.entity_type', $entity_type);

    // Update the entity type in order to remove the 'langcode' field.     \Drupal::entityDefinitionUpdateManager()->updateFieldableEntityType($entity_type, \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type->id()));

    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow$this->revEntityTypeId, $this->revEntityTypeId);

    // Check that the tested entity type is not translatable and does not have a     // 'langcode' entity key.     $entity_type = $this->entityTypeManager->getDefinition($this->revEntityTypeId);
    $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.');
    $this->assertFalse($entity_type->getKey('langcode'), "The test entity type does not have a 'langcode' entity key.");

    // Create a test entity.
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. */
  protected function updateEntityTypeToRevisionable($perform_update = FALSE) {
    $translatable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isTranslatable();

    
/** * 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']);
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
    $schema_handler = $this->database->schema();
    
Home | Imprint | This part of the site doesn't use cookies.