3 namespace Drupal\Tests\video_embed_field\Kernel;
6 * Test helpers for loading entities for tests.
8 trait EntityLoadTrait {
11 * Load an entity by it's label.
13 * @param string $label
14 * The label of the entity to load.
15 * @param string $entity_type
16 * The entity type to load.
18 * @return \Drupal\Core\Entity\EntityInterface
21 protected function loadEntityByLabel($label, $entity_type = 'node') {
22 $type_manager = \Drupal::entityTypeManager();
23 $label_key = $type_manager->getDefinition($entity_type)->getKey('label');
24 $entities = \Drupal::entityQuery($entity_type)->condition($label_key, $label, '=')->execute();
25 return $type_manager->getStorage($entity_type)->load(array_shift($entities));