You are here

private function MultichoiceQuestion::_normalizeAlternative in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::_normalizeAlternative()

Helper function. Normalizes alternatives.

Parameters

array $alternatives:

Return value

array

2 calls to MultichoiceQuestion::_normalizeAlternative()
MultichoiceQuestion::insertAlternative in question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php
Helper function. Saves new alternatives.
MultichoiceQuestion::updateAlternative in question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php
Helper function. Updates existing alternatives.

File

question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php, line 212

Class

MultichoiceQuestion
@QuizQuestion ( id = "multichoice", label = Plugin annotation @Translation("Multiple choice question"), handlers = { "response" = "\Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse" } )

Namespace

Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion

Code

private function _normalizeAlternative($alternatives) {
  $copy = $alternatives;

  // Answer and answer format.
  if (is_array($alternatives['answer'])) {
    $copy['answer'] = array_key_exists('value', $alternatives['answer']) ? $alternatives['answer']['value'] : NULL;
    $copy['answer_format'] = array_key_exists('format', $alternatives['answer']) ? $alternatives['answer']['format'] : NULL;
  }

  // Feedback if chosen and feedback if chosen format.
  if (is_array($alternatives['feedback_if_chosen'])) {
    $copy['feedback_if_chosen'] = array_key_exists('value', $alternatives['feedback_if_chosen']) ? $alternatives['feedback_if_chosen']['value'] : NULL;
    $copy['feedback_if_chosen_format'] = array_key_exists('format', $alternatives['feedback_if_chosen']) ? $alternatives['feedback_if_chosen']['format'] : NULL;
  }

  // Feedback if not chosen and feedback if not chosen format.
  if (is_array($alternatives['feedback_if_not_chosen'])) {
    $copy['feedback_if_not_chosen'] = array_key_exists('value', $alternatives['feedback_if_not_chosen']) ? $alternatives['feedback_if_not_chosen']['value'] : NULL;
    $copy['feedback_if_not_chosen_format'] = array_key_exists('format', $alternatives['feedback_if_not_chosen']) ? $alternatives['feedback_if_not_chosen']['format'] : NULL;
  }
  return $copy;
}