You are here

public function CalendarLinkTwigExtension::calendarLink in Calendar Link 8

Same name and namespace in other branches
  1. 2.x 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
Class CalendarLinkTwigExtension.

Namespace

Drupal\calendar_link\Twig

Code

public function calendarLink($type, $title, $from, $to, $all_day = FALSE, $description = '', $address = '') {
  if (!isset(self::$types[$type])) {
    throw new CalendarLinkException($this
      ->t('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($this
      ->t('Invalid calendar link data.'));
  }
  if ($description) {
    $link
      ->description($description);
  }
  if ($address) {
    $link
      ->address($address);
  }
  return $link
    ->{$type}();
}