<?php

use Drupal\Core\Render\Markup;

/**
 * Implements hook_preprocess_page_title().
 */
function kuria_smg_preprocess_page_title(&$variables) {
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    if ($node->bundle() == 'palyazat') {

      $overridden_title = '<span class="field field--name-title field--type-string field--label-hidden">';
      $overridden_title .= 'A ' . $node->label();
      $overridden_title .= '</span>';
      $variables['title'] = Markup::create($overridden_title);
    }
  }
}

function kuria_smg_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'event_photos') {
    if (in_array($variables['node']->bundle(), ['press', 'sajto'])) {
      unset($variables['label']);
    }
  }
}

function kuria_smg_preprocess_breadcrumb(&$variables) {
  // Case: https://atrium.macroweb.hu/kuria/node/35121#comment-174555
  foreach ($variables['breadcrumb'] as $index => $item) {
    if (!$item['text']) {
      unset($variables['breadcrumb'][$index]);
    }
  }
}

/* Allow is_front to be used on other templates */
function kuria_smg_preprocess(&$variables, $hook) {
  try {
    $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
  }
  catch (Exception $e) {
    $variables['is_front'] = FALSE;
  }
  // Ensure the cache varies correctly (new in Drupal 8.3).
  $variables['#cache']['contexts'][] = 'url.path.is_front';
  // base_path legyen minden template-ben
  $variables['base_path'] = base_path();
  // base_url legyen minden template-ben
  $host = \Drupal::request()->getSchemeAndHttpHost();
  $variables['host'] = $host;
}
