On this page
public function EntityRepository::loadEntityByConfigTarget
public EntityRepository::loadEntityByConfigTarget($entity_type_id, $target)
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.
Throws
\Drupal\Core\Entity\EntityStorageException Thrown if the target identifier is a UUID but the entity type does not support UUIDs.
Overrides EntityRepositoryInterface::loadEntityByConfigTarget
See also
\Drupal\Core\Entity\EntityInterface::getConfigTarget()
File
- core/lib/Drupal/Core/Entity/EntityRepository.php, line 60
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);
}
// For content entities, the config target is given by the UUID.
else {
$entity = $this->loadEntityByUuid($entity_type_id, $target);
}
return $entity;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityRepository.php/function/EntityRepository::loadEntityByConfigTarget/8.1.x