Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides Twig functions to easily generate links for adding events to popular calendar services like Google Calendar, Apple iCal, and Outlook. It can create links for individual services or a list of links for all supported calendars.

About

Calendar link provides two Twig functions for generating links for various calendaring services.

Requirements

This module does not require any additional modules outside of Drupal core.

This module uses the spatie/calendar-links library as its foundation. Use composer to install the module (see INSTALLATION) or run composer require spatie/calendar-links separately.

Installation

Configuration

There is no configuration available for this module.

Use

This module provides two new Twig functions for generating calendar link URLs:

  1. calendar_link: Returns a string link for a specific calendar type. Available types are:
    • Apple iCal/Microsoft Outlook (ics)
    • Google calendar (google)
    • Office 365 (webOffice) (version 3.x only)
    • Outlook.com (webOutlook)
    • Yahoo! calendar (yahoo)
  2. calendar_links: Returns an array of links for all available calendar types. Each array element has the following keys/data:
    • type_key: The calendar type key (ics, google, etc.)
    • type_name: The calendar type name ("iCal", "Google", etc.)
    • url: The URL for the calendar item

Examples

Assume an example "Event" node with the extras fields:

  • Title (string title)
  • Start date/time (datetime field_start)
  • End date/time (datetime field_end)
  • All day event (boolean field_all_day)
  • Description (string field_description)
  • Location (string field_location)

In a twig template, the following code with generate a link to the event to a Google calendar:

{% set link = calendar_link('google', node.title, node.field_start, node.field_end, node.field_all_day, node.field_description, node.field_location) %}
<a href="{{ link }}">Add to Google</a>

Or, to create a list of links for each service:

{% set links = calendar_links(node.title, node.field_start, node.field_end, node.field_all_day, node.field_description, node.field_location) %}
<ul>
{% for link in links %}
  <li>
    <a href="{{ link.url }}" class="calendar-link-{{ link.type_key }}">{{ link.type_name }}</a>
  </li>
{% endfor %}
</ul>

Using with Views

When using values from Views results only the default formatter for date fields is supported. Most other date field formatters do not provide necessary timezone data in rendered results to ensure correctness of the generated calendar links. See #3249457: Views support for further details and discussion.

Activity

Total releases
1
First release
Dec 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
3.0.4 Stable Dec 12, 2024