function social_topic_preprocess_node in Open Social 8.9
Same name and namespace in other branches
- 8 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.2 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.3 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.4 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.5 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.6 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.7 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 8.8 modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 10.3.x modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 10.0.x modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 10.1.x modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
- 10.2.x modules/social_features/social_topic/social_topic.module \social_topic_preprocess_node()
Prepares variables for node templates.
Default template: node.html.twig.
Most themes use their own copy of node.html.twig. The default is located inside "/core/modules/node/templates/node.html.twig". Look in there for the full list of variables.
Parameters
array $variables: An associative array containing:
- elements: An array of elements to display in view mode.
- node: The node object.
- view_mode: View mode; e.g., 'full', 'teaser', etc.
File
- modules/
social_features/ social_topic/ social_topic.module, line 37 - The Social topic module.
Code
function social_topic_preprocess_node(array &$variables) {
/* @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];
if ($node
->getType() === 'topic') {
$topic_type = $node
->get('field_topic_type');
$topic_type_entities = $topic_type
->referencedEntities();
if (count($topic_type_entities) === 1) {
$curr_langcode = \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
foreach ($topic_type_entities as $topic) {
if ($topic
->isTranslatable() && $topic
->hasTranslation($curr_langcode)) {
$topic = $topic
->getTranslation($curr_langcode);
}
$variables['metadata'] = t('in @topic', [
'@topic' => $topic
->link(),
]);
// Set topic type link.
$topic_type_url = Url::fromRoute('view.latest_topics.page_latest_topics', [
'field_topic_type_target_id' => $topic
->id(),
]);
$topic_type_link = Link::fromTextAndUrl($topic
->label(), $topic_type_url)
->toString();
$variables['topic_type'] = $topic_type_link;
}
}
else {
$variables['metadata'] = NULL;
$variables['topic_type'] = NULL;
}
}
}