You are here

function quiz_question_node_view in Quiz 8.4

Same name and namespace in other branches
  1. 7.4 question_types/quiz_question/quiz_question.module \quiz_question_node_view()
  2. 7.5 question_types/quiz_question/quiz_question.module \quiz_question_node_view()

Implements hook_node_view().

File

question_types/quiz_question/quiz_question.module, line 574
Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.

Code

function quiz_question_node_view(\Drupal\Core\Entity\EntityInterface $node, \Drupal\entity\Entity\EntityDisplay $display, $view_mode, $langcode) {
  $q_types = array_keys(_quiz_question_get_implementations());
  if (in_array($node
    ->getType(), $q_types)) {
    drupal_add_css(drupal_get_path('module', 'quiz') . '/quiz.css');
    if ($view_mode == 'search_index' && !\Drupal::config('quiz_question.settings')
      ->get('quiz_index_questions')) {
      $node->body = '';
      $node->content = array();
      $node->title = '';
      $node->taxonomy = array();

      //return $node;
    }
    $content = '';
    if (_quiz_is_taking_context()) {

      /*
       * @todo: I see no reason why this should be a part of view anymore.
       * In quiz 5 we should stop using hook_view to view the answering form
       */
      $form = drupal_get_form('quiz_question_answering_form', $node);
      $form_markup = drupal_render($form);
      if (!empty($form_markup)) {
        $node->content['body'] = array(
          '#markup' => $form_markup,
        );
      }
    }
    elseif ($view_mode == 'teaser') {
      $node->content['question_teaser'] = _quiz_question_teaser_content($node);
    }
    else {

      // normal node view

      //$question = _quiz_question_get_instance($node, TRUE);
      $content = _quiz_question_get_instance($node, TRUE)
        ->getNodeView();
    }

    // put it into the node->content
    if (!empty($content)) {
      $node->content = isset($node->content) ? $node->content + $content : $content;
    }
  }
}