You are here

function quiz_node_presave in Quiz 8.6

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_node_presave()
  2. 8.5 quiz.module \quiz_node_presave()
  3. 7.6 quiz.module \quiz_node_presave()
  4. 7 quiz.module \quiz_node_presave()
  5. 7.4 quiz.module \quiz_node_presave()
  6. 7.5 quiz.module \quiz_node_presave()

Implements hook_node_presave().

File

./quiz.module, line 317
Contains quiz.module

Code

function quiz_node_presave($node) {
  if ($node->type == 'quiz') {

    // Convert the action id to the actual id from the MD5 hash.
    // Why the actions module does this I do not know? Maybe to prevent
    // invalid values put into the options value="" field.
    if (!empty($node->aid) && ($aid = actions_function_lookup($node->aid))) {
      $node->aid = $aid;
    }
    if (Drupal::config('quiz.settings')
      ->get('auto_revisioning', 1)) {
      $node->revision = quiz_has_been_answered($node) ? 1 : 0;
    }

    // If this is a programmatic save, ensure we use the defaults.
    $defaults = quiz_get_defaults();
    foreach ($defaults as $property => $value) {
      if (!isset($node->{$property})) {
        $node->{$property} = $defaults->{$property};
      }
    }
  }
  if (isset($node->is_quiz_question) && Drupal::config('quiz.settings')
    ->get('auto_revisioning', 1)) {
    $node->revision = quiz_question_has_been_answered($node) ? 1 : 0;
  }
}