You are here

protected function EntityDefinitionTestTrait::getUpdatedEntityTypeDefinition in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::getUpdatedEntityTypeDefinition()

Returns an entity type definition, possibly updated to be rev or mul.

Parameters

bool $revisionable: (optional) Whether the entity type should be revisionable or not. Defaults to FALSE.

bool $translatable: (optional) Whether the entity type should be translatable or not. Defaults to FALSE.

Return value

\Drupal\Core\Entity\EntityTypeInterface An entity type definition.

11 calls to EntityDefinitionTestTrait::getUpdatedEntityTypeDefinition()
EntityDefinitionTestTrait::resetEntityType in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Resets the entity type definition.
EntityDefinitionTestTrait::updateEntityTypeToNotRevisionable in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Updates the 'entity_test_update' entity type not revisionable.
EntityDefinitionTestTrait::updateEntityTypeToNotTranslatable in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Updates the 'entity_test_update' entity type to not translatable.
EntityDefinitionTestTrait::updateEntityTypeToRevisionable in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Updates the 'entity_test_update' entity type to revisionable.
EntityDefinitionTestTrait::updateEntityTypeToRevisionableAndTranslatable in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Updates the 'entity_test_update' entity type to revisionable and translatable.

... See full list

File

core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php, line 439

Class

EntityDefinitionTestTrait
Provides some test methods used to update existing entity definitions.

Namespace

Drupal\Tests\system\Functional\Entity\Traits

Code

protected function getUpdatedEntityTypeDefinition($revisionable = FALSE, $translatable = FALSE) {
  $entity_type = clone \Drupal::entityTypeManager()
    ->getDefinition('entity_test_update');
  if ($revisionable) {
    $keys = $entity_type
      ->getKeys();
    $keys['revision'] = 'revision_id';
    $entity_type
      ->set('entity_keys', $keys);
    $entity_type
      ->set('revision_table', 'entity_test_update_revision');
  }
  else {
    $keys = $entity_type
      ->getKeys();
    $keys['revision'] = '';
    $entity_type
      ->set('entity_keys', $keys);
    $entity_type
      ->set('revision_table', NULL);
  }
  if ($translatable) {
    $entity_type
      ->set('translatable', TRUE);
    $entity_type
      ->set('data_table', 'entity_test_update_data');
  }
  else {
    $entity_type
      ->set('translatable', FALSE);
    $entity_type
      ->set('data_table', NULL);
  }
  if ($revisionable && $translatable) {
    $entity_type
      ->set('revision_data_table', 'entity_test_update_revision_data');
  }
  else {
    $entity_type
      ->set('revision_data_table', NULL);
  }
  $this->state
    ->set('entity_test_update.entity_type', $entity_type);
  $this->container
    ->get('entity_type.manager')
    ->clearCachedDefinitions();
  $this->container
    ->get('entity_type.bundle.info')
    ->clearCachedBundles();
  $this->container
    ->get('entity_field.manager')
    ->clearCachedFieldDefinitions();
  return $entity_type;
}