function social_tagging_process_tags in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.2 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.3 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.4 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.5 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.6 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 8.8 modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 10.3.x modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 10.0.x modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 10.1.x modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
- 10.2.x modules/social_features/social_tagging/social_tagging.module \social_tagging_process_tags()
Build output on node view.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: A node.
Return value
array Hierarchic presentation of the terms.
2 calls to social_tagging_process_tags()
- SocialGroupTagsBlock::build in modules/
social_features/ social_tagging/ src/ Plugin/ Block/ SocialGroupTagsBlock.php - Builds and returns the renderable array for this block plugin.
- SocialTagsBlock::build in modules/
social_features/ social_tagging/ src/ Plugin/ Block/ SocialTagsBlock.php - Builds and returns the renderable array for this block plugin.
File
- modules/
social_features/ social_tagging/ social_tagging.module, line 295 - Contains social_tagging.module.
Code
function social_tagging_process_tags(EntityInterface $entity) {
if (!($entity instanceof EntityInterface && $entity
->hasField('social_tagging'))) {
return [];
}
$tag_service = \Drupal::service('social_tagging.tag_service');
if (!$tag_service
->active()) {
return [];
}
$terms = $entity
->get('social_tagging')
->getValue();
if ($tag_service
->allowSplit()) {
$renderable = [
'#theme' => 'social_tagging_split',
'#taghierarchy' => $tag_service
->buildHierarchy($terms, $entity
->getEntityTypeId()),
];
}
else {
$tarray = [];
// Determine the route based on the source of the tags.
$route = 'view.search_content.page_no_value';
if ($entity
->getEntityTypeId() == 'group') {
$route = 'view.search_groups.page_no_value';
}
// Just a simple way to add all tags to the array.
foreach ($terms as $term) {
$url = Url::fromRoute($route, [
'tag[]' => $term['target_id'],
]);
/** @var Drupal\taxonomy\Entity\Term $term */
$taxonomy_term = Term::load($term['target_id']);
$tarray[$taxonomy_term
->getName()] = $url
->toString();
}
$renderable = [
'#theme' => 'social_tagging_nosplit',
'#tagstitle' => t('Tags'),
'#tags' => $tarray,
];
}
return \Drupal::service('renderer')
->render($renderable);
}