function EntityRepository::loadEntityByConfigTarget

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::loadEntityByConfigTarget()
  2. 10 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::loadEntityByConfigTarget()
  3. 11.x core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::loadEntityByConfigTarget()

Overrides EntityRepositoryInterface::loadEntityByConfigTarget

File

core/lib/Drupal/Core/Entity/EntityRepository.php, line 71

Class

EntityRepository
Provides several mechanisms for retrieving entities.

Namespace

Drupal\Core\Entity

Code

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.