You are here

public function Quiz::delete in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::delete()
  2. 8.5 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 488

Class

Quiz
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

public function delete() {
  $entities = \Drupal::entityTypeManager()
    ->getStorage('quiz_question_relationship')
    ->loadByProperties([
    'quiz_id' => $this
      ->id(),
  ]);
  foreach ($entities as $entity) {
    $entity
      ->delete();
  }
  $entities = \Drupal::entityTypeManager()
    ->getStorage('quiz_result')
    ->loadByProperties([
    'qid' => $this
      ->id(),
  ]);
  foreach ($entities as $entity) {
    $entity
      ->delete();
  }
  parent::delete();
}