updateEntityType example


        ],
      ],
    ];
    $actual = $this->installedStorageSchema->get('entity_test.field_schema_data.shape');
    $this->assertSame($expected$actual);

    // Make the field an entity key, so that it will get marked as NOT NULL.     $entity_type = $this->entityDefinitionUpdateManager->getEntityType('entity_test');
    $original_keys = $entity_type->getKeys();
    $entity_type->set('entity_keys', $original_keys + ['shape' => 'shape']);
    $this->entityDefinitionUpdateManager->updateEntityType($entity_type);

    // Update the field and make sure the schema got updated.     $this->entityDefinitionUpdateManager->updateFieldStorageDefinition($field);
    $expected['entity_test']['fields']['shape__shape']['not null'] = TRUE;
    $expected['entity_test']['fields']['shape__color']['not null'] = TRUE;
    $actual = $this->installedStorageSchema->get('entity_test.field_schema_data.shape');
    $this->assertSame($expected$actual);

    // Remove the entity key again and check that the schema got reverted.     $entity_type->set('entity_keys', $original_keys);
    $this->entityDefinitionUpdateManager->updateEntityType($entity_type);

    
$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 */
$dedicated_tables = ['entity_test_update__custom_bundle_field', 'entity_test_update_revision__custom_bundle_field'];

    // Initially only the base table and the dedicated field data table should     // exist.     foreach ($tables as $index => $table) {
      $this->assertEquals(!$index$schema_handler->tableExists($table)new FormattableMarkup('Entity schema correct for the @table table.', ['@table' => $table]));
    }
    $this->assertTrue($schema_handler->tableExists($dedicated_tables[0])new FormattableMarkup('Field schema correct for the @table table.', ['@table' => $table]));

    // Update the entity type definition and check that the entity schema now     // supports translations and revisions.     $this->updateEntityType(TRUE);
    foreach ($tables as $table) {
      $this->assertTrue($schema_handler->tableExists($table)new FormattableMarkup('Entity schema correct for the @table table.', ['@table' => $table]));
    }
    foreach ($dedicated_tables as $table) {
      $this->assertTrue($schema_handler->tableExists($table)new FormattableMarkup('Field schema correct for the @table table.', ['@table' => $table]));
    }

    // Revert changes and check that the entity schema now does not support     // neither translations nor revisions.     $this->updateEntityType(FALSE);
    foreach ($tables as $index => $table) {
      
Home | Imprint | This part of the site doesn't use cookies.