You are here

public function QuizQuestionRelationship::save in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizQuestionRelationship.php \Drupal\quiz\Entity\QuizQuestionRelationship::save()
  2. 6.x src/Entity/QuizQuestionRelationship.php \Drupal\quiz\Entity\QuizQuestionRelationship::save()

Saves an entity permanently.

When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

Overrides EntityBase::save

File

src/Entity/QuizQuestionRelationship.php, line 96

Class

QuizQuestionRelationship
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

public function save() {
  if ($this
    ->isNew() && $this
    ->getQuiz()
    ->get('randomization')
    ->getString() == 2) {

    // If the quiz has radomized questions, mark as a not required random
    // question.
    $this
      ->set('question_status', QUIZ_QUESTION_RANDOM);
  }
  if ($this
    ->get('auto_update_max_score')
    ->getString()) {
    $this
      ->set('max_score', $this
      ->get('question_id')
      ->referencedEntities()[0]
      ->get('max_score')
      ->getString());
  }
  parent::save();
}