You are here

public function EntityLoadHelper::loadByProperties in YAML Content 8

Load an existing entity by property data.

Some entity types require special handling and will be handled uniquely.

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.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

See also

\Drupal\yaml_content\Service\EntityLoadHelper::$requiresSpecialHandling

1 call to EntityLoadHelper::loadByProperties()
EntityLoadHelper::loadEntity in src/Service/EntityLoadHelper.php
Load an entity matching content data if available.

File

src/Service/EntityLoadHelper.php, line 184

Class

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

Namespace

Drupal\yaml_content\Service

Code

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

  // Address entities requiring special handling separately.
  // [#2893055] Until this is resolved, these entities are not loaded.
  if (in_array($entity_type, $this::$requiresSpecialHandling)) {

    // @todo Add system to process these entities specifically.
    return FALSE;
  }

  // Load the entity type storage handler.
  $entity_handler = $this
    ->getEntityStorage($entity_type);
  $properties = $this
    ->extractContentProperties($entity_type, $content_data);
  $entity_ids = $entity_handler
    ->loadByProperties($properties);
  return reset($entity_ids);
}