You are here

function faq_view in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 5.2 faq.module \faq_view()
  2. 5 faq.module \faq_view()
  3. 6 faq.module \faq_view()

Implements hook_view().

File

./faq.module, line 348
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function faq_view($node, $view_mode) {
  drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
  $detailed_question = FALSE;

  // Get the detailed question.
  if ($field_items = field_get_items('node', $node, 'field_detailed_question')) {
    $detailed_question = reset($field_items);
  }

  // Only show the detailed question if there is something to show.
  if ($detailed_question && !empty($detailed_question['safe_value'])) {
    $show_question = FALSE;
    if ($view_mode == 'full') {

      // The detailed question is always shown on the full node.
      $show_question = TRUE;
    }
    else {

      // On other pages, consider the admin settings.
      if (variable_get('faq_question_length', 'short') == 'both' && variable_get('faq_display', 'questions_top') == 'hide_answer') {
        $show_question = TRUE;
      }
    }

    // Should be handled by theming - create field--field_detailed_question.tpl.php.
    if ($show_question) {

      // We're here if we are showing the question.
      $node->content['field_detailed_question'] = array(
        '#markup' => theme('field_detailed_question', $detailed_question),
      );
    }
    else {

      // We switch off the visibility of the detailed question.
      hide($node->content['field_detailed_question']);
    }
  }
  return $node;
}