function _social_event_addtocal_get_links 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_get_links()
- 10.0.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \_social_event_addtocal_get_links()
- 10.1.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \_social_event_addtocal_get_links()
- 10.2.x modules/social_features/social_event/modules/social_event_addtocal/social_event_addtocal.module \_social_event_addtocal_get_links()
Adds links for the 'Add to Calendar' button.
Parameters
\Drupal\node\NodeInterface $node: The node entity.
Return value
array[] Array of links for render.
1 call to _social_event_addtocal_get_links()
- social_event_addtocal_node_view in modules/
social_features/ social_event/ modules/ social_event_addtocal/ social_event_addtocal.module - Implements hook_ENTITY_TYPE_view().
File
- modules/
social_features/ social_event/ modules/ social_event_addtocal/ social_event_addtocal.module, line 76 - Contains Social Add To Calendar module.
Code
function _social_event_addtocal_get_links(NodeInterface $node) {
// Links for Add to calendar button.
$links = [];
// Get 'Add to calendar' configuration.
$addtocal_config = Drupal::config('social_event_addtocal.settings');
// Get plugin instance and set links array.
/** @var \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarManager $social_add_to_calendar */
$social_add_to_calendar = Drupal::service('plugin.manager.social_add_to_calendar');
// Get allowed calendars.
$allowed_calendars = $addtocal_config
->get('allowed_calendars');
// Set links for dropdown.
foreach ($allowed_calendars as $allowed_calendar) {
// Check if calendar plugin enabled in config.
if ($allowed_calendar) {
/** @var \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarInterface $calendar */
$calendar = $social_add_to_calendar
->createInstance($allowed_calendar);
// Exit if calendar plugin nor exist.
if (!$calendar instanceof SocialAddToCalendarInterface) {
continue;
}
// Set link for plugin instance.
$links[] = [
'title' => $calendar
->getName(),
'url' => $calendar
->generateUrl($node),
];
}
}
// Change title if only one calendar enabled.
if (count($links) === 1) {
$links[0]['title'] = t('Add to Calendar');
}
return $links;
}