function social_event_addtocal_node_view in Open Social 8.9
Same name and namespace in other branches
- 10.3.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \social_event_addtocal_node_view()
- 10.0.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \social_event_addtocal_node_view()
- 10.1.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \social_event_addtocal_node_view()
- 10.2.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \social_event_addtocal_node_view()
Implements hook_ENTITY_TYPE_view().
Uses for node entity type.
File
- modules/
social_features/ social_event/ modules/ social_event_addtocal/ social_event_addtocal.module, line 32 - Contains Social Add To Calendar module.
Code
function social_event_addtocal_node_view(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) {
if ($node
->bundle() !== 'event') {
return;
}
// Get 'Add to calendar' configuration.
$addtocal_config = Drupal::config('social_event_addtocal.settings');
// Set render array if the 'Add to calendar' feature enabled.
if ($addtocal_config
->get('enable_add_to_calendar')) {
// Get calendar links.
$links = _social_event_addtocal_get_links($node);
// Update the 'Add to calendar' field rendering.
$build['field_event_addtocal'] = [
'#type' => 'dropbutton',
'#attributes' => [
'class' => [
'add-to-calendar',
],
],
'#links' => $links,
];
// Make sure we clear the cache if the settings is submitted.
$build['#cache']['tags'][] = 'config:social_event_addtocal.settings';
// Split links if there is more than one.
if (count($links) > 1) {
$build['field_event_addtocal']['#attributes']['no-split'] = [
'title' => t('Add to Calendar'),
'alignment' => 'right',
];
}
}
}