You are here

public function EntityLoadHelper::loadEntity in YAML Content 8

Load an entity matching content data if available.

Loading by `uuid` will be prioritized if one is defined in order to support updating of entity properties when a unique match is defined.

If a `uuid` property is not defined, an entity matching defined properties is searched for instead.

Parameters

string $entity_type: The type of entity being imported.

array $content_data: The import content structure representing the entity being searched for.

Return value

\Drupal\Core\Entity\EntityInterface|false Return a matching entity if one is found, or FALSE otherwise.

1 call to EntityLoadHelper::loadEntity()
EntityLoadHelper::entityExists in src/Service/EntityLoadHelper.php
Query if a target entity already exists and should be updated.

File

src/Service/EntityLoadHelper.php, line 102

Class

EntityLoadHelper
A helper class to support identification and loading of existing entities.

Namespace

Drupal\yaml_content\Service

Code

public function loadEntity($entity_type, array $content_data) {

  // Prioritize loading by UUID to enable changing of properties if a
  // confident match is identified.
  if (isset($content_data['uuid'])) {
    $entity = $this
      ->loadByUuid($entity_type, $content_data['uuid']);
  }
  else {
    $entity = $this
      ->loadByProperties($entity_type, $content_data);
  }
  return $entity;
}