function ContentEntityStorageBase::preLoad

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::preLoad()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::preLoad()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::preLoad()

Overrides EntityStorageBase::preLoad

1 call to ContentEntityStorageBase::preLoad()
ContentEntityStorageBase::loadUnchanged in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Loads an unchanged entity from the database.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 600

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function preLoad(?array &$ids = NULL) {
    $entities = [];
    // Call hook_entity_preload().
    $preload_ids = $ids ?: [];
    $preload_entities = $this->moduleHandler()
        ->invokeAll('entity_preload', [
        $preload_ids,
        $this->entityTypeId,
    ]);
    foreach ((array) $preload_entities as $entity) {
        $entities[$entity->id()] = $entity;
    }
    if ($entities) {
        // If any entities were pre-loaded, remove them from the IDs still to
        // load.
        if ($ids !== NULL) {
            $ids = array_keys(array_diff_key(array_flip($ids), $entities));
        }
        else {
            $result = $this->getQuery()
                ->accessCheck(FALSE)
                ->condition($this->entityType
                ->getKey('id'), array_keys($entities), 'NOT IN')
                ->execute();
            $ids = array_values($result);
        }
    }
    return $entities;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.