Interim commit.
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Kernel / EntityLoadTrait.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Kernel;
4
5 /**
6  * Test helpers for loading entities for tests.
7  */
8 trait EntityLoadTrait {
9
10   /**
11    * Load an entity by it's label.
12    *
13    * @param string $label
14    *   The label of the entity to load.
15    * @param string $entity_type
16    *   The entity type to load.
17    *
18    * @return \Drupal\Core\Entity\EntityInterface
19    *   A loaded entity.
20    */
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));
26   }
27
28 }