function DefaultContentModerationStateRevisionUpdateTest::getEntityByLabel

Load an entity by label.

Parameters

string $entity_type_id: The entity type ID.

string $label: The label of the entity to load.

Return value

\Drupal\Core\Entity\ContentEntityInterface The loaded entity.

1 call to DefaultContentModerationStateRevisionUpdateTest::getEntityByLabel()
DefaultContentModerationStateRevisionUpdateTest::testUpdateDefaultRevision in core/modules/content_moderation/tests/src/Functional/Update/DefaultContentModerationStateRevisionUpdateTest.php
Test updating the default revision.

File

core/modules/content_moderation/tests/src/Functional/Update/DefaultContentModerationStateRevisionUpdateTest.php, line 106

Class

DefaultContentModerationStateRevisionUpdateTest
Test updating the ContentModerationState entity default revisions.

Namespace

Drupal\Tests\content_moderation\Functional\Update

Code

protected function getEntityByLabel($entity_type_id, $label) {
    $entity_type_manager = $this->container
        ->get('entity_type.manager');
    $label_field = $entity_type_manager->getDefinition($entity_type_id)
        ->getKey('label');
    $entity_list = $entity_type_manager->getStorage($entity_type_id)
        ->loadByProperties([
        $label_field => $label,
    ]);
    return array_shift($entity_list);
}

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