function EntityStorageBase::loadByProperties
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::loadByProperties()
- 10 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::loadByProperties()
- 9 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::loadByProperties()
- 8.9.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::loadByProperties()
Load entities by their property values without any access checks.
Parameters
array $values: An associative array where the keys are the property names and the values are the values those properties must have. If a property takes multiple values, passing an array of values will produce an IN condition.
Return value
\Drupal\Core\Entity\EntityInterface[] An array of entity objects indexed by their ids.
Overrides EntityStorageInterface::loadByProperties
3 methods override EntityStorageBase::loadByProperties()
- ContentEntityNullStorage::loadByProperties in core/
lib/ Drupal/ Core/ Entity/ ContentEntityNullStorage.php - Load entities by their property values without any access checks.
- FieldConfigStorage::loadByProperties in core/
modules/ field/ src/ FieldConfigStorage.php - Load entities by their property values without any access checks.
- FieldStorageConfigStorage::loadByProperties in core/
modules/ field/ src/ FieldStorageConfigStorage.php - Load entities by their property values without any access checks.
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php, line 656
Class
- EntityStorageBase
- A base entity storage class.
Namespace
Drupal\Core\EntityCode
public function loadByProperties(array $values = []) {
$cid = NULL;
if ($this->entityType
->isStaticallyCacheable() && \array_keys($values) === [
'uuid',
] && \is_string($values['uuid'])) {
// Check if we have already loaded or queried this entity by its UUID.
// @see ::setStaticCache
$cid = \sprintf('uuid_lookup:%s:%s', $this->entityTypeId, $values['uuid']);
$cache = $this->memoryCache
->get($cid);
if ($cache !== FALSE) {
return $cache->data !== NULL ? $this->loadMultiple($cache->data) : [];
}
}
$entity_query = $this->getQuery();
$entity_query->accessCheck(FALSE);
$this->buildPropertyQuery($entity_query, $values);
$result = $entity_query->execute();
if ($cid !== NULL) {
// Store the result of the UUID query to avoid repeating the same query.
$this->memoryCache
->set($cid, $result, MemoryCacheInterface::CACHE_PERMANENT, [
$this->uuidMemoryCacheTag,
]);
}
return $result ? $this->loadMultiple($result) : [];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.