You are here

protected function EntityLoadTrait::loadEntityByLabel in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/EntityLoadTrait.php \Drupal\Tests\video_embed_field\Kernel\EntityLoadTrait::loadEntityByLabel()

Load an entity by it's label.

Parameters

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

string $entity_type: The entity type to load.

Return value

\Drupal\Core\Entity\EntityInterface A loaded entity.

2 calls to EntityLoadTrait::loadEntityByLabel()
Drupal6EmfieldMigrationTest::testEmfieldMigration in tests/src/Kernel/Drupal6EmfieldMigrationTest.php
Test the emfield migration.
Drupal7MigrationTest::testMigration in tests/src/Kernel/Drupal7MigrationTest.php
Test the emfield migration.

File

tests/src/Kernel/EntityLoadTrait.php, line 21

Class

EntityLoadTrait
Test helpers for loading entities for tests.

Namespace

Drupal\Tests\video_embed_field\Kernel

Code

protected function loadEntityByLabel($label, $entity_type = 'node') {
  $type_manager = \Drupal::entityTypeManager();
  $label_key = $type_manager
    ->getDefinition($entity_type)
    ->getKey('label');
  $entities = \Drupal::entityQuery($entity_type)
    ->condition($label_key, $label, '=')
    ->execute();
  return $type_manager
    ->getStorage($entity_type)
    ->load(array_shift($entities));
}