You are here

function template_preprocess_bat_event_series in Booking and Availability Management Tools for Drupal 8

Prepares variables for Event Series templates.

Default template: bat_event_series.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An associative array containing the user information and any
  • attributes: HTML attributes for the containing element.

File

modules/bat_event_series/bat_event_series.module, line 384

Code

function template_preprocess_bat_event_series(array &$variables) {

  // Fetch Event series Entity Object.
  $event_series = $variables['elements']['#bat_event_series'];

  // Helpful $content variable for templates.
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  $start = new \DateTime($event_series
    ->get('event_dates')->value);
  $rrule = new RRule($event_series
    ->getRRule(), $start);
  $rrule_human_readable = ucfirst($rrule
    ->humanReadable([
    'date_formatter' => 'bat_event_series_rrule_date_formatter',
  ]));
  $variables['content']['rrule'] = [
    '#markup' => '<h2>' . t('RRule') . '</h2><div>' . $rrule_human_readable . '</div>',
  ];
  $variables['content']['events_label'] = [
    '#markup' => '<h2>' . t('Events') . '</h2>',
  ];
  $variables['content']['events'] = views_embed_view('event_series', 'events', $event_series
    ->id());
}