public function SocialProfileTagService::getCategories in Open Social 10.3.x
Same name and namespace in other branches
- 10.2.x modules/social_features/social_profile/src/SocialProfileTagService.php \Drupal\social_profile\SocialProfileTagService::getCategories()
Returns all the top level term items, that are considered categories.
Return value
array An array of top level category items.
Overrides SocialProfileTagServiceInterface::getCategories
1 call to SocialProfileTagService::getCategories()
- SocialProfileTagService::hasContent in modules/
social_features/ social_profile/ src/ SocialProfileTagService.php - Returns if there are any taxonomy items available.
File
- modules/
social_features/ social_profile/ src/ SocialProfileTagService.php, line 87
Class
- SocialProfileTagService
- Provide a service for profile tagging.
Namespace
Drupal\social_profileCode
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->taxonomyStorage
->loadTree('profile_tag', 0, 1, FALSE, $current_lang))) {
$options = $this
->prepareTermOptions($current_lang_terms);
}
elseif (!empty($default_lang_terms = $this->taxonomyStorage
->loadTree('profile_tag', 0, 1, FALSE))) {
$options = $this
->prepareTermOptions($default_lang_terms);
}
// Return array.
return $options;
}