<?php

/**
 * @file
 * Functions to support theming modules in the Toc GA theme.
 */

/**
 * Preprocess card_blocks by machine name.
 * This is above the fold, so we are giving the images 'eager' not 'lazy' (default).
 */
function toc_ga_preprocess_card_block__front_banner_blocks(&$vars) {
  $entities = $vars['element']['entities_raw'];
  $items = [];
  foreach ($entities as $entity) {
    /* @var \Drupal\eck\Entity\EckEntity $entity */
    $extras = $entity->__get('extras') ?? [];
    $extras['card_image_loading'] = 'eager';
    $entity->__set('extras', $extras);
    $view_builder = \Drupal::entityTypeManager()->getViewBuilder('card_block');
    $items[] = $view_builder->view($entity);
  }
  if (!empty($items) && ($vars['batch'] >= 1)) {
    $vars['items'] = $items;
    $vars['slides'] = array_chunk($items, $vars['batch']);
  }
}

/**
 * Preprocess for buy_tickets_header().
 *
 * For GA we are just adding the default tablet view port tabs state.
 *
 * @param array $vars
 *   Theme variables.
 */
function toc_ga_preprocess_buy_tickets_header(array &$vars) {
  $vars['tablet_tabs_closed'] = TRUE;
}
