function EntityTestTest::createEntity

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/EntityTestTest.php \Drupal\Tests\jsonapi\Functional\EntityTestTest::createEntity()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/EntityTestTest.php \Drupal\Tests\jsonapi\Functional\EntityTestTest::createEntity()
  3. 10 core/modules/jsonapi/tests/src/Functional/EntityTestTest.php \Drupal\Tests\jsonapi\Functional\EntityTestTest::createEntity()

Overrides ResourceTestBase::createEntity

File

core/modules/jsonapi/tests/src/Functional/EntityTestTest.php, line 75

Class

EntityTestTest
JSON:API integration test for the "EntityTest" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function createEntity() {
    // Set flag so that internal field 'internal_string_field' is created.
    // @see entity_test_entity_base_field_info()
    $this->container
        ->get('state')
        ->set('entity_test.internal_field', TRUE);
    $field_storage_definition = BaseFieldDefinition::create('string')->setLabel('Internal field')
        ->setInternal(TRUE);
    \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('internal_string_field', 'entity_test', 'entity_test', $field_storage_definition);
    $entity_test = EntityTest::create([
        'name' => 'Llama',
        'type' => 'entity_test',
        // Set a value for the internal field to confirm that it will not be
        // returned in normalization.
        // @see entity_test_entity_base_field_info().
'internal_string_field' => [
            'value' => 'This value shall not be internal!',
        ],
    ]);
    $entity_test->setOwnerId(0);
    $entity_test->save();
    return $entity_test;
}

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