You are here

protected function EntityDefinitionTestTrait::addBaseField 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::addBaseField()

Adds a new base field to the 'entity_test_update' entity type.

Parameters

string $type: (optional) The field type for the new field. Defaults to 'string'.

string $entity_type_id: (optional) The entity type ID the base field should be attached to. Defaults to 'entity_test_update'.

bool $is_revisionable: (optional) If the base field should be revisionable or not. Defaults to FALSE.

bool $set_label: (optional) If the base field should have a label or not. Defaults to TRUE.

bool $is_translatable: (optional) If the base field should be translatable or not. Defaults to FALSE.

10 calls to EntityDefinitionTestTrait::addBaseField()
EntityDefinitionTestTrait::modifyBaseField in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Modifies the new base field from 'string' to 'text'.
EntityDefinitionUpdateTest::testBaseFieldCreateDeleteWithExistingEntities in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests creating and deleting a base field if entities exist.
EntityDefinitionUpdateTest::testBaseFieldCreateUpdateDeleteWithoutData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests creating, updating, and deleting a base field if no entities exist.
EntityDefinitionUpdateTest::testBaseFieldDeleteWithExistingData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests deleting a base field when it has existing data.
EntityDefinitionUpdateTest::testBaseFieldEntityKeyUpdateWithExistingData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests updating a base field when it has existing data.

... See full list

File

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

Class

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

Namespace

Drupal\Tests\system\Functional\Entity\Traits

Code

protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE, $set_label = TRUE, $is_translatable = FALSE) {
  $definitions['new_base_field'] = BaseFieldDefinition::create($type)
    ->setName('new_base_field')
    ->setRevisionable($is_revisionable)
    ->setTranslatable($is_translatable);
  if ($set_label) {
    $definitions['new_base_field']
      ->setLabel(t('A new base field'));
  }
  $this->state
    ->set($entity_type_id . '.additional_base_field_definitions', $definitions);
}