function ResourceTestBase::getEntityDuplicate

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate()
4 calls to ResourceTestBase::getEntityDuplicate()
FeedTest::createAnotherEntity in core/modules/aggregator/tests/src/Functional/Jsonapi/FeedTest.php
Creates another entity to be tested.
ItemTest::createAnotherEntity in core/modules/aggregator/tests/src/Functional/Jsonapi/ItemTest.php
Creates another entity to be tested.
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 426

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getEntityDuplicate(EntityInterface $original, $key) {
    $duplicate = $original->createDuplicate();
    if ($label_key = $original->getEntityType()
        ->getKey('label')) {
        $duplicate->set($label_key, $original->label() . '_' . $key);
    }
    if ($duplicate instanceof ConfigEntityInterface && ($id_key = $duplicate->getEntityType()
        ->getKey('id'))) {
        $id = $original->id();
        $duplicate->set($id_key, $id . '_' . $key);
    }
    return $duplicate;
}

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