public function CalendarLinkTwigExtension::calendarLink in Calendar Link 2.x
Same name and namespace in other branches
- 8 src/Twig/CalendarLinkTwigExtension.php \Drupal\calendar_link\Twig\CalendarLinkTwigExtension::calendarLink()
Create a calendar link.
Parameters
string $type: Generator key to use for link building.
string $title: Calendar entry title.
\Drupal\Core\Datetime\DrupalDateTime|\DateTime $from: Calendar entry start date and time.
\Drupal\Core\Datetime\DrupalDateTime|\DateTime $to: Calendar entry end date and time.
bool $all_day: Indicator for an "all day" calendar entry.
string $description: Calendar entry description.
string $address: Calendar entry address.
Return value
string URL for the specific calendar type.
1 call to CalendarLinkTwigExtension::calendarLink()
- CalendarLinkTwigExtension::calendarLinks in src/
Twig/ CalendarLinkTwigExtension.php - Create links for all calendar types.
File
- src/
Twig/ CalendarLinkTwigExtension.php, line 71
Class
- CalendarLinkTwigExtension
- Twig extensions class for the `calendar_link` and `calender_links` functions.
Namespace
Drupal\calendar_link\TwigCode
public function calendarLink($type, $title, $from, $to, $all_day = FALSE, $description = '', $address = '') {
if (!isset(self::$types[$type])) {
throw new CalendarLinkException('Invalid calendar link type.');
}
try {
if ($from instanceof DrupalDateTime) {
$from = $from
->getPhpDateTime();
}
if ($to instanceof DrupalDateTime) {
$to = $to
->getPhpDateTime();
}
$link = Link::create($title, $from, $to, $all_day);
} catch (InvalidLink $e) {
throw new CalendarLinkException('Invalid calendar link data.');
}
if ($description) {
$link
->description($description);
}
if ($address) {
$link
->address($address);
}
return $link
->{$type}();
}