Skip to content
Snippets Groups Projects
asc_bootstrap.theme 3.28 KiB
<?php
/**
 * @file
 * Bootstrap sub-theme.
 *
 * Place your custom PHP code in this file.
 */

function asc_bootstrap_preprocess_page(&$vars, $hook) {
 // Render the library as laid out in herchel.libraries.yml
 $libraries['#attached']['library'][] = 'asc_bootstrap/asc_bootstrap-corescripts';
 drupal_render($libraries);

 //adds site name variable which is used as logo alt and title text
 $vars['site_name'] = \Drupal::config('system.site')->get('name');

 $vars['osu_logo'] = theme_get_setting('osu_logo','asc_bootstrap');
}

//create another suggestion based on the block type

/* function asc_bootstrap_theme_suggestions_block_alter(array &$suggestions, array $variables) {

function asc_bootstrap_theme_suggestions_block_alter(array &$suggestions, array $variables) {
>>>>>>> a03c8d80522d837a9acc6a1213d7ad7e61dc9e51
  // Block suggestions for custom block bundles.
  if (isset($variables['elements']['content']['#block_content'])) {
    array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
  }
} */

/*
* adds content type to theme suggestions so that landing page doesn't default to page.html.twig
*/
function asc_bootstrap_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    $content_type = $node->bundle();
    $suggestions[] = 'page__'.$content_type;
  }
}

/*
* adds content type to variable to be used in paragraph twig files.
*/
function asc_bootstrap_preprocess_paragraph(&$variables) {
  $node = \Drupal::request()->attributes->get('node');
  $variables['page_content_type'] = $node->getType();
}


function asc_bootstrap_preprocess_block(&$vars) {
 $vars['site_mail'] = \Drupal::config('system.site')->get('mail');
}

/*
* alters news and events filters so that AJAX doesn't remove headings, etc. upon request
*/
function asc_bootstrap_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if (($form['#id'] == 'views-exposed-form-events-page-1')||($form['#id'] == '#views-exposed-form-news-page-1')) {
    /*
    * add new HTML content to filters (headers and spacer)
    * and setting weights for where they should appear in the form hierarchy
    */
    $form['filter_heading'] = array(
      '#markup' => '<h3 class="filter-heading">Filter</h3>',
      '#weight' => -10,
    );
    $form['filter_search_heading'] = array(
      '#markup' => '<h3 class="filter-heading search-heading">Search</h3>',
      '#weight' => 4,
    );
    $form['spacer'] = array(
      '#markup' => '<div class="filter-spacer"></div>',
      '#weight' => 1.5,
    );
    /*
    * setting up weights for form elements
    */
    $form['field_evt_date_range_value']['#weight'] = 1;
    $form['field_evt_taxonomy_target_id_1']['#weight'] = 2;
    $form['field_evt_taxonomy_target_id']['#weight'] = 3;
    $form['keys']['#weight'] = 5;
    $form['keys']['#attributes']['placeholder'] = t('Search Keywords');

    /*
    * checking if taxonomy has vocabulary - if not, don't display field
    */
    if(count($form['field_evt_taxonomy_target_id']['#options']) == 1) {
      $form['field_evt_taxonomy_target_id']['#access'] = FALSE;
    }

    if(count($form['field_evt_taxonomy_target_id_1']['#options']) == 1) {
      $form['field_evt_taxonomy_target_id_1']['#access'] = FALSE;
    }
  }
}