You are here

protected function QuizResultAnswerStorage::mapFromStorageRecords in Quiz 6.x

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

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

Overrides SqlContentEntityStorage::mapFromStorageRecords

File

src/Storage/QuizResultAnswerStorage.php, line 35

Class

QuizResultAnswerStorage

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['handlers']['response']) {
      $this->entityClass = $ret['handlers']['response'];
    }
    else {
      $this->entityClass = 'Drupal\\quiz\\Entity\\QuizResultAnswerBroken';
    }
    $entities = parent::mapFromStorageRecords([
      $id => $record,
    ], $load_from_revision);
    $out += $entities;
  }
  return $out;
}