You are here

protected function ContentEntityStorage::loadFromMongo in MongoDB 8

Loads entity records from a MongoDB collections.

Parameters

string $prefix:

array $find:

Return value

array

2 calls to ContentEntityStorage::loadFromMongo()
ContentEntityStorage::doLoadMultiple in src/Entity/ContentEntityStorage.php
Performs storage-specific loading of entities.
ContentEntityStorage::loadRevision in src/Entity/ContentEntityStorage.php
Load a specific entity revision.

File

src/Entity/ContentEntityStorage.php, line 81
Contains Drupal\mongodb\Entity\ContentEntityStorage.

Class

ContentEntityStorage

Namespace

Drupal\mongodb\Entity

Code

protected function loadFromMongo($prefix, array $find) {
  $collection = $this->mongo
    ->get($prefix . '.' . $this->entityType
    ->id());
  $return = array();
  $langcode_key = $this->entityType
    ->getKey('langcode');
  $default_langcode_key = $this->entityType
    ->getKey('default_langcode');
  $revision_key = $this->entityType
    ->getKey('revision');
  $translatable = $this->entityType
    ->isTranslatable();
  foreach ($collection
    ->find($find) as $record) {
    $data = array();
    $definitions = $this->entityManager
      ->getFieldDefinitions($this->entityTypeId, $record['bundle']);
    $this
      ->mongoToEntityData($data, $record, $definitions, $translatable, $default_langcode_key, $langcode_key);
    if ($prefix == 'entity_revision') {

      // Add non-revisionable data from the current revision.
      $entity_record = $this->mongo
        ->get('entity.' . $this->entityType
        ->id())
        ->findOne([
        '_id' => $record['entity_id'],
      ]);
      $definitions = array_filter($this->entityManager
        ->getFieldStorageDefinitions($this->entityTypeId), function (FieldStorageDefinitionInterface $definition) use ($revision_key) {
        return !$definition
          ->isRevisionable() && $definition
          ->getName() != $revision_key;
      });
      $this
        ->mongoToEntityData($data, $entity_record, $definitions, $translatable, $default_langcode_key, $langcode_key);
      if ($entity_record['values'][0][$this->entityType
        ->getKey('revision')][0]['value'] != $record['_id']) {
        $data['isDefaultRevision'][LanguageInterface::LANGCODE_DEFAULT] = FALSE;
      }
    }
    $return[$record['_id']] = new $this->entityClass($data, $this->entityTypeId, $record['bundle'], $record['translations']);
  }
  return $return;
}