function ResourceTestBase::getEntityDuplicate
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
- 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
- 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
2 calls to ResourceTestBase::getEntityDuplicate()
- ResourceTestBase::createAnotherEntity in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Creates another entity to be tested.
- UserTest::createAnotherEntity in core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php - Creates another entity to be tested.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 421
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function getEntityDuplicate(EntityInterface $original, $key) {
$duplicate = $original->createDuplicate();
if ($label_key = $original->getEntityType()
->getKey('label')) {
$duplicate->set($label_key, $original->label() . '_' . $key);
}
$id_key = $duplicate->getEntityType()
->getKey('id');
$needs_manual_id = $duplicate instanceof ConfigEntityInterface && $id_key;
if ($duplicate instanceof FieldableEntityInterface && $id_key) {
$id_field = $duplicate->getFieldDefinition($id_key);
if ($id_field->getType() !== 'integer') {
$needs_manual_id = TRUE;
}
}
if ($needs_manual_id) {
$duplicate->set($id_key, $original->id() . '_' . $key);
}
return $duplicate;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.