function EntityTestResourceTestBase::createEntity

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestResourceTestBase.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase::createEntity()
  2. 10 core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestResourceTestBase.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase::createEntity()

File

core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestResourceTestBase.php, line 70

Class

EntityTestResourceTestBase

Namespace

Drupal\Tests\entity_test\Functional\Rest

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);
  $this->applyEntityUpdates('entity_test');
  $entity_test = \Drupal::entityTypeManager()->getStorage(static::$entityTypeId)
    ->create([
    'name' => 'Llama',
    'type' => static::$entityTypeId,
    // 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.