You are here

public function SocialTaggingService::getCategories in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  2. 8.2 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  3. 8.3 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  4. 8.4 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  5. 8.5 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  6. 8.6 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  7. 8.7 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  8. 8.8 modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  9. 10.3.x modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  10. 10.0.x modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  11. 10.1.x modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()
  12. 10.2.x modules/social_features/social_tagging/src/SocialTaggingService.php \Drupal\social_tagging\SocialTaggingService::getCategories()

Returns all the top level term items, that are considered categories.

Return value

array An array of top level category items.

2 calls to SocialTaggingService::getCategories()
SocialTaggingService::getAllChildren in modules/social_features/social_tagging/src/SocialTaggingService.php
Returns all the children of top level term items.
SocialTaggingService::hasContent in modules/social_features/social_tagging/src/SocialTaggingService.php
Returns if there are any taxonomy items available.

File

modules/social_features/social_tagging/src/SocialTaggingService.php, line 111

Class

SocialTaggingService
Provides a custom tagging service.

Namespace

Drupal\social_tagging

Code

public function getCategories() {

  // Define as array.
  $options = [];

  // Get the site's current language.
  $current_lang = $this->languageManager
    ->getCurrentLanguage()
    ->getId();

  // Fetch main categories.
  // If the website is multilingual, we want to first check for the terms
  // in current language. At the moment, users do not add proper language to
  // vocabulary terms which may result in return of empty array on loadTree()
  // function. So, we want to check for the terms also in default language if
  // we don't find terms in current language.
  if (!empty($current_lang_terms = $this->termStorage
    ->loadTree('social_tagging', 0, 1, FALSE, $current_lang))) {
    $options = $this
      ->prepareTermOptions($current_lang_terms);
  }
  elseif (!empty($default_lang_terms = $this->termStorage
    ->loadTree('social_tagging', 0, 1, FALSE))) {
    $options = $this
      ->prepareTermOptions($default_lang_terms);
  }

  // Return array.
  return $options;
}