function EntityDefinitionTestTrait::addBundleField

Same name in this branch
  1. 8.9.x core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php \Drupal\system\Tests\Entity\EntityDefinitionTestTrait::addBundleField()
Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::addBundleField()
  2. 10 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::addBundleField()
  3. 11.x core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait::addBundleField()

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

Parameters

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

bool $revisionable: (optional) Whether the field should be revisionable. Defaults to FALSE.

bool $translatable: (optional) Whether the field should be translatable. Defaults to FALSE.

7 calls to EntityDefinitionTestTrait::addBundleField()
EntityDefinitionTestTrait::modifyBundleField in core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
Modifies the new bundle field from 'string' to 'text'.
EntityDefinitionUpdateTest::testBundleFieldCreateDeleteWithExistingEntities in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests creating and deleting a bundle field if entities exist.
EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests creating, updating, and deleting a bundle field if no entities exist.
EntityDefinitionUpdateTest::testBundleFieldDeleteWithExistingData in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests deleting a bundle field when it has existing data.
EntityDefinitionUpdateTest::testBundleFieldUpdateWithEntityTypeSchemaUpdate in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Tests updating a bundle field when the entity type schema has changed.

... See full list

File

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

Class

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

Namespace

Drupal\Tests\system\Functional\Entity\Traits

Code

protected function addBundleField($type = 'string', $revisionable = FALSE, $translatable = FALSE) {
    $definitions['new_bundle_field'] = FieldStorageDefinition::create($type)->setName('new_bundle_field')
        ->setLabel(t('A new bundle field'))
        ->setTargetEntityTypeId('entity_test_update')
        ->setRevisionable($revisionable)
        ->setTranslatable($translatable);
    $this->state
        ->set('entity_test_update.additional_field_storage_definitions', $definitions);
    $this->state
        ->set('entity_test_update.additional_bundle_field_definitions.test_bundle', $definitions);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.