<?php

/**
 * @file
 * Functions to support theming content in the Toc Master theme.
 */

/**
 * Preprocess hook for eck_entity__link_block__$ID().
 */
function toc_sr_preprocess_eck_entity__link_block__smartcard(&$vars) {
  $vars['block_class'] = 'bl-vh cbelianr bl-lilfr py-lg-2 px-lg-3 mb-4 sr-lb-signup';
  $vars['title_display'] = 'noflex';
}

/**
 * Preprocess hook for node__dog_offer().
 */
function toc_sr_preprocess_node__dog_offer(&$vars) {
  _toc_sr_preprocess_offers($vars, 'dog_offer');
}

/**
 * Preprocess hook for node__dog_offer().
 */
function toc_sr_preprocess_node__offer(&$vars) {
  _toc_sr_preprocess_offers($vars, 'offer');
}

/**
 * Preprocess for both types of offer nodes.
 *
 * @param $vars
 *
 * @return void
 */
function _toc_sr_preprocess_offers(&$vars, $type = '') {
  // Here we are formatting the back link. Everything else is from TOC Master.
  $entity = $vars['node'];
  $offers_config = \Drupal::service('config.factory')->getEditable('offers_content_type.settings');
  $back_link = $offers_config->get('offer_listings_path');
  $offer_category_terms_string = _tm_misc_get_field_content($entity, 'field_of_category');
  $tags = _tm_misc_format_tags_views_filter_links($offer_category_terms_string, $back_link, 'ocat');
  $vars['tags'] = $tags;
  // Hide Intro text for offers as the template has logic to override main.
  $allowed = ['br', 'p', 'ul', 'ol', 'li', 'a', 'em', 'strong', 'h2'];
  $text_format = _tm_text_format($allowed, 0);
  $main_text = _tm_misc_get_field_content($entity, 'field_of_long_description', 'render', $text_format);
  if ($type == 'offer') {
    $vars['intro_text'] = FALSE;
  }
  $vars['main_text'] = $main_text;
}

/**
 * Preprocess hook for eck_entity__the_list_events().
 * Used for the event place.
 */
function toc_sr_preprocess_eck_entity__the_list_events(&$vars) {
  // SR currently don't want to show the booking link button because
  // the layout doesn't work when there is two buttons and lots of categories
  // and they say it isn't needed
  $vars['booking_link_url'] = FALSE;
}
