public function Quiz::delete in Quiz 8.5
Same name and namespace in other branches
- 8.6 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::delete()
 - 6.x src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::delete()
 
Delete all quiz results and question relationships when a quiz is deleted.
@todo This should probably gather keys instead of loading all entities and looping through to ensure their hooks get fired.
Overrides EntityBase::delete
File
- src/
Entity/ Quiz.php, line 486  
Class
- Quiz
 - Defines the Quiz entity class.
 
Namespace
Drupal\quiz\EntityCode
public function delete() {
  $entities = \Drupal::entityTypeManager()
    ->getStorage('quiz_question_relationship')
    ->loadByProperties([
    'quiz_id' => $this
      ->id(),
  ]);
  foreach ($entities as $entity) {
    $entity
      ->delete();
  }
  //Drupal::entityTypeManager()->getStorage('quiz_question_relationship')->delete($entities);
  $entities = \Drupal::entityTypeManager()
    ->getStorage('quiz_result')
    ->loadByProperties([
    'qid' => $this
      ->id(),
  ]);
  foreach ($entities as $entity) {
    $entity
      ->delete();
  }
  //Drupal::entityTypeManager()->getStorage('quiz_result')->delete($entities);
  parent::delete();
}