You are here

function template_preprocess_addtocal_links in Add to Cal 8.2

Prepares variables for addtocal link templates.

Default template: addtocal-links.html.twig.

Parameters

array $variables: An associative array containing:

  • addtocal_link: A Link object used for generating add to cal links.
  • id: Unique id for the addtocal button and menu.
  • attributes: An associative array of element attributes.
  • button_text: The addtocal button text.
  • button_attributes: An associative array of button attributes.
  • menu_attributes: An associative array of menu attributes.
  • items: List of add to cal links, each containing a title and generator.

File

./addtocal.module, line 46

Code

function template_preprocess_addtocal_links(&$variables) {
  $link = $variables['addtocal_link'];
  if ($link instanceof \Spatie\CalendarLinks\Link) {
    foreach ($variables['items'] as $delta => $item) {
      $generator = $item['generator'] ?? NULL;
      if ($generator instanceof \Spatie\CalendarLinks\Generator) {
        $variables['items'][$delta]['url'] = $link
          ->formatWith($generator);
      }
    }
  }
  $attributes = new Attribute($variables['attributes']);
  $attributes
    ->addClass('addtocal-container');
  $variables['attributes'] = $attributes;
  $button_attributes = new Attribute($variables['button_attributes']);
  $button_attributes
    ->addClass('addtocal');
  $button_attributes
    ->setAttribute('id', $variables['id']);
  $variables['button_attributes'] = $button_attributes;
  $menu_attributes = new Attribute($variables['menu_attributes']);
  $menu_attributes
    ->addClass('addtocal-menu');
  $menu_attributes
    ->setAttribute('id', $variables['id'] . '-menu');
  $variables['menu_attributes'] = $menu_attributes;
}