protected function ResourceTestBase::createAnotherEntity in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::createAnotherEntity()
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::createAnotherEntity()
Creates another entity to be tested.
Parameters
mixed $key: A unique key to be used for the ID and/or label of the duplicated entity.
Return value
\Drupal\Core\Entity\EntityInterface Another entity based on $this->entity.
Throws
\Drupal\Core\Entity\EntityStorageException
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 411
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function createAnotherEntity($key) {
$duplicate = $this
->getEntityDuplicate($this->entity, $key);
// Some entity types are not stored, hence they cannot be reloaded.
if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) {
$duplicate
->set('field_rest_test', 'Second collection entity');
}
$duplicate
->save();
return $duplicate;
}