function EntityRepository::loadEntityByConfigTarget
Loads an entity by the config target identifier.
Parameters
string $entity_type_id: The entity type ID to load from.
string $target: The configuration target to load, as returned from \Drupal\Core\Entity\EntityInterface::getConfigTarget().
Return value
\Drupal\Core\Entity\EntityInterface|null The entity object, or NULL if there is no entity with the given config target identifier.
Overrides EntityRepositoryInterface::loadEntityByConfigTarget
File
- 
              core/lib/ Drupal/ Core/ Entity/ EntityRepository.php, line 72 
Class
- EntityRepository
- Provides several mechanisms for retrieving entities.
Namespace
Drupal\Core\EntityCode
public function loadEntityByConfigTarget($entity_type_id, $target) {
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  // For configuration entities, the config target is given by the entity ID.
  // @todo Consider adding a method to allow entity types to indicate the
  //   target identifier key rather than hard-coding this check. Issue:
  //   https://www.drupal.org/node/2412983.
  if ($entity_type instanceof ConfigEntityTypeInterface) {
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->load($target);
  }
  else {
    $entity = $this->loadEntityByUuid($entity_type_id, $target);
  }
  return $entity;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
