function quiz_node_prepare in Quiz 8.6
Same name and namespace in other branches
- 8.5 quiz.module \quiz_node_prepare()
- 7.6 quiz.module \quiz_node_prepare()
- 7 quiz.module \quiz_node_prepare()
- 7.4 quiz.module \quiz_node_prepare()
- 7.5 quiz.module \quiz_node_prepare()
Implements hook_node_prepare().
File
- ./
quiz.module, line 346 - Contains quiz.module
Code
function quiz_node_prepare($node) {
if ($node->type == 'quiz' && !isset($node->nid)) {
// If this is a new node we apply the user defaults for the quiz settings.
if (arg(0) == 'node') {
$user = Drupal::currentUser();
if (!node_load_multiple(array(), array(
'uid' => $user
->id(),
'type' => 'quiz',
))) {
Drupal::messenger()
->addMessage(t('You are making your first @quiz. On this page you set the attributes, most of which you may tell the system to remember as defaults for the future. On the next screen you can add questions.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
}
}
$settings = quiz_get_defaults();
foreach ($settings as $key => $value) {
if (!isset($node->{$key})) {
$node->{$key} = $value;
}
}
}
if (isset($node->is_quiz_question)) {
if (Drupal::config('quiz.settings')
->get('auto_revisioning', 1)) {
$node->revision = quiz_question_has_been_answered($node) ? 1 : 0;
}
}
}