You are here

function faq_view_question in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 6 faq.module \faq_view_question()
  2. 7.2 faq.module \faq_view_question()

Helper function to setup the faq question.

Parameters

array &$data: Array reference to store display data in.

object $node: The node object.

string $path: The path/url which the question should link to if links are disabled.

string $anchor: Link anchor to use in question links.

7 calls to faq_view_question()
template_preprocess_faq_category_hide_answer in includes/faq.hide_answer.inc
Create categorized FAQ page if set to show answer when question is clicked.
template_preprocess_faq_category_questions_inline in includes/faq.questions_inline.inc
Create categorized FAQ page if set to show/hide the questions inline.
template_preprocess_faq_category_questions_top in includes/faq.questions_top.inc
Create categorized questions for FAQ page if set to show questions on top.
template_preprocess_faq_category_questions_top_answers in includes/faq.questions_top.inc
Create categorized answers for FAQ page if set to show the questions on top.
template_preprocess_faq_hide_answer in includes/faq.hide_answer.inc
Create FAQ page if set to show/hide answer when question is clicked.

... See full list

File

./faq.module, line 1185
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_question(&$data, $node, $path = NULL, $anchor = NULL) {
  $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  $question = '';

  // Don't link to faq node, instead provide no link, or link to current page.
  if ($disable_node_links) {
    if (empty($path) && empty($anchor)) {
      $question = check_plain($node->title);
    }
    elseif (empty($path)) {

      // Can't seem to use l() function with empty string as screen-readers
      // don't like it, so create anchor name manually.
      $question = '<a id="' . $anchor . '"></a>' . check_plain($node->title);
    }
    else {
      $options = array();
      if ($anchor) {
        $options['attributes'] = array(
          'id' => $anchor,
        );
      }
      $question = l($node->title, $path, $options);
    }
  }
  else {
    if (empty($anchor)) {
      $question = l($node->title, "node/{$node->nid}");
    }
    else {
      $question = l($node->title, "node/{$node->nid}", array(
        "attributes" => array(
          "id" => "{$anchor}",
        ),
      ));
    }
  }
  $question = '<span datatype="" property="dc:title">' . $question . '</span>';

  // Get the language of the body field.
  $language = 'und';
  foreach ($node->body as $lang => $values) {
    if ($values[0]['value']) {
      $language = $lang;
    }
  }

  // Get the detailed question.
  $detailed_question = array();
  if ($dq = field_get_items('node', $node, 'field_detailed_question')) {
    $detailed_question = reset($dq);
  }
  if (variable_get('faq_display', 'questions_top') != 'hide_answer' && !empty($detailed_question['safe_value']) && variable_get('faq_question_length', 'short') == 'both') {
    $question .= '<div class="faq-detailed-question">' . $detailed_question['safe_value'] . '</div>';
  }
  $data['question'] = $question;
}