You are here

public static function FaqHelper::viewChildCategoryHeaders in Frequently Asked Questions 8

Helper function to setup the list of sub-categories for the header.

Parameters

$term: The term to setup the list of child terms for.

Return value

An array of sub-categories.

4 calls to FaqHelper::viewChildCategoryHeaders()
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_new_page in includes/faq.new_page.inc
Create categorized FAQ page if set to show answer in a new page.
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.

File

src/FaqHelper.php, line 177

Class

FaqHelper
Contains static helper functions for FAQ module.

Namespace

Drupal\faq

Code

public static function viewChildCategoryHeaders($term) {
  $child_categories = array();
  $list = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadChildren($term
    ->id());
  foreach ($list as $tid => $child_term) {
    $term_node_count = FaqHelper::taxonomyTermCountNodes($child_term
      ->id());
    if ($term_node_count) {

      // Get taxonomy image.
      $term_image = '';

      // taxonomy_image does not exists in D8 yet
      // if (module_exists('taxonomy_image')) {
      //  $term_image = taxonomy_image_display($child_term->tid, array('class' => 'faq-tax-image'));
      // }.
      $child_term_id = $child_term
        ->id();
      $term_vars['link'] = Link::fromTextAndUrl(t($child_term
        ->getName()), Url::fromUserInput('/faq-page/' . $child_term_id));
      $term_vars['description'] = $child_term
        ->getDescription() ? t($child_term
        ->getDescription()) : '';
      $term_vars['count'] = $term_node_count;
      $term_vars['term_image'] = $term_image;
      $child_categories[] = $term_vars;
    }
  }
  return $child_categories;
}