You are here

public function QuizQuestion::getNodeForm in Quiz 7.5

Same name and namespace in other branches
  1. 6.4 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::getNodeForm()
  2. 7.6 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::getNodeForm()
  3. 7 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::getNodeForm()
  4. 7.4 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::getNodeForm()

Returns a node form to quiz_question_form.

Adds default form elements, and fetches question type specific elements from their implementation of getCreationForm.

Parameters

array $form_state:

Return value

array An renderable FAPI array.

File

question_types/quiz_question/quiz_question.core.inc, line 91
Classes used in the Quiz Question module.

Class

QuizQuestion
A base implementation of a quiz_question.

Code

public function getNodeForm(array &$form_state = NULL) {
  global $user;
  $form = array();

  // Mark this form to be processed by quiz_form_alter. quiz_form_alter will
  // among other things hide the revision fieldset if the user don't have
  // permission to control the revisioning manually.
  $form['#quiz_check_revision_access'] = TRUE;

  // Allow user to set title?
  if (user_access('edit question titles')) {
    $form['helper']['#theme'] = 'quiz_question_creation_form';
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#maxlength' => 255,
      '#default_value' => $this->node->title,
      '#required' => TRUE,
      '#description' => t('Add a title that will help distinguish this question from other questions. This will not be seen during the @quiz.', array(
        '@quiz' => QUIZ_NAME,
      )),
    );
  }
  else {
    $form['title'] = array(
      '#type' => 'value',
      '#value' => $this->node->title,
    );
  }

  // Store quiz id in the form.
  $form['quiz_nid'] = array(
    '#type' => 'hidden',
  );
  $form['quiz_vid'] = array(
    '#type' => 'hidden',
  );
  if (isset($_GET['quiz_nid']) && isset($_GET['quiz_vid'])) {
    $form['quiz_nid']['#value'] = intval($_GET['quiz_nid']);
    $form['quiz_vid']['#value'] = intval($_GET['quiz_vid']);
  }

  // Identify this node as a quiz question type so that it can be recognized
  // by other modules effectively.
  $form['is_quiz_question'] = array(
    '#type' => 'value',
    '#value' => TRUE,
  );
  if (!empty($this->node->nid)) {
    if ($properties = entity_load('quiz_question', FALSE, array(
      'nid' => $this->node->nid,
      'vid' => $this->node->vid,
    ))) {
      $quiz_question = reset($properties);
    }
  }
  $form['feedback'] = array(
    '#type' => 'text_format',
    '#title' => t('Question feedback'),
    '#default_value' => !empty($quiz_question->feedback) ? $quiz_question->feedback : '',
    '#format' => !empty($quiz_question->feedback_format) ? $quiz_question->feedback_format : filter_default_format(),
    '#description' => t('This feedback will show when configured and the user answers a question, regardless of correctness.'),
  );

  // Add question type specific content.
  $form = array_merge($form, $this
    ->getCreationForm($form_state));
  if (variable_get('quiz_auto_revisioning', 1) && $this
    ->hasBeenAnswered()) {
    $log = t('The current revision has been answered. We create a new revision so that the reports from the existing answers stays correct.');
    $this->node->revision = 1;
    $this->node->log = $log;
  }
  return $form;
}