You are here

function quiz_node_prepare_form in Quiz 8.4

Implementation of hook_node_prepare_form().

File

./quiz.module, line 2461
Quiz Module

Code

function quiz_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) {
  if ($node
    ->getType() == 'quiz' && $node
    ->isNew()) {

    // If this is a new node we apply the user defaults for the quiz settings.
    $settings = _quiz_load_user_settings();
    if (!$settings) {
      if (arg(0) == 'node') {
        drupal_set_message(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_NAME,
        )));
      }
      $settings = _quiz_load_user_settings(\Drupal::config('quiz.settings')
        ->get('quiz_def_uid'));
    }
    $settings += _quiz_get_node_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('quiz_auto_revisioning')) {
      $node->revision = quiz_question_has_been_answered($node) ? 1 : 0;
    }
  }
}