You are here

function template_preprocess_faq_questions_top in Frequently Asked Questions 8

Same name and namespace in other branches
  1. 6 includes/faq.questions_top.inc \template_preprocess_faq_questions_top()
  2. 7.2 includes/faq.questions_top.inc \template_preprocess_faq_questions_top()
  3. 7 includes/faq.questions_top.inc \template_preprocess_faq_questions_top()

Create the structure of the page, when the questions are to be shown on top.

Parameters

&$variables: Array reference of arguments given to the theme() function.

Return value

A variable holding the HTML formatted page.

File

includes/faq.questions_top.inc, line 21
FAQ page callbacks for the "questions top" layouts.

Code

function template_preprocess_faq_questions_top(&$variables) {
  $faq_settings = \Drupal::config('faq.settings');
  $data = $variables['data'];

  // Fetch configuration.
  $teaser = $faq_settings
    ->get('use_teaser');

  // Configure labels.
  $variables['question_label'] = '';
  $variables['answer_label'] = '';
  if ($faq_settings
    ->get('qa_mark')) {
    $variables['question_label'] = $faq_settings
      ->get('question_label');
    $variables['answer_label'] = $faq_settings
      ->get('answer_label');
  }
  $this_page = Url::fromRoute('<current>');

  // Loop through results.
  $questions = array();
  $answers = array();
  $key = 0;
  foreach ($data as $node) {
    $anchor = 'n' . $node
      ->id();
    $this_page
      ->setOptions(array(
      'fragment' => $anchor,
    ));
    $questions[$key] = Link::fromTextAndUrl($node
      ->getTitle(), $this_page)
      ->toString();
    FaqViewer::viewQuestion($answers[$key], $node, NULL, $anchor);
    FaqViewer::viewAnswer($answers[$key], $node, $teaser);
    $key++;
  }
  $variables['limit'] = $key;
  $list_style = $faq_settings
    ->get('question_listing');
  $variables['list_style'] = $list_style;
  $variables['use_teaser'] = $teaser;
  $variables['questions'] = $questions;
  $variables['answers'] = $answers;
  $item_list = array(
    '#theme' => 'item_list',
    '#items' => $questions,
    '#title' => t('Content'),
    '#list_type' => $list_style,
  );
  $variables['questions_list'] = \Drupal::service('renderer')
    ->render($item_list);
}