You are here

protected function QuizQuestionStorage::mapFromStorageRecords in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Storage/QuizQuestionStorage.php \Drupal\quiz\Storage\QuizQuestionStorage::mapFromStorageRecords()
  2. 6.x src/Storage/QuizQuestionStorage.php \Drupal\quiz\Storage\QuizQuestionStorage::mapFromStorageRecords()

When loading from the database, map any object to its respective class.

Overrides SqlContentEntityStorage::mapFromStorageRecords

File

src/Storage/QuizQuestionStorage.php, line 35

Class

QuizQuestionStorage

Namespace

Drupal\quiz\Storage

Code

protected function mapFromStorageRecords(array $records, $load_from_revision = FALSE) {
  $pluginManager = Drupal::service('plugin.manager.quiz.question');
  $plugins = $pluginManager
    ->getDefinitions();
  $out = [];
  foreach ($records as $id => $record) {
    $ret = $plugins[$record->type];
    if ($ret['class']) {
      $this->entityClass = $ret['class'];
    }
    else {
      $this->entityClass = \Drupal\quiz\Entity\QuizQuestionBroken::class;
    }
    $entities = parent::mapFromStorageRecords([
      $id => $record,
    ], $load_from_revision);
    $out += $entities;
  }
  return $out;
}