Newer
Older
use \Drupal\taxonomy\Entity\Term;
use \Drupal\taxonomy\Entity\Vocabulary;
/**
* @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::service('renderer')->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');
Brian Canini
committed
function asc_bootstrap_preprocess_node(&$vars, $hook) {
$vars['site_mail'] = \Drupal::config('system.site')->get('mail');
$vars['site_name'] = \Drupal::config('system.site')->get('name');
//get pathauto url alias for event
$config = \Drupal::service('config.factory')->get('pathauto.pattern.events');
$evpattern = explode('/', $config->get('pattern'));
$vars['evpattern'] = $evpattern[0];
//get research landing page url alias
$nids = \Drupal::entityQuery('node')->condition('type','research_landing_page')->execute();
$lid = array_shift($nids);
$vars['resrch_landing'] = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$lid);
//get research gallery landing page url alias
$nids2 = \Drupal::entityQuery('node')->condition('type','research_gallery_landing_page')->execute();
$lid2 = array_shift($nids2);
$vars['resrch_gall_landing'] = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$lid2);
Brian Canini
committed
}
Brian Canini
committed
/*
* 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) {
// Add content type suggestions.
if (($node = \Drupal::request()->attributes->get('node')) && (strpos($_SERVER['REQUEST_URI'], "revisions") == false)) {
array_splice($suggestions, 1, 0, 'page__' . $node->getType());
Brian Canini
committed
}
}
Brian Canini
committed
/*
* adds content type to variable to be used in paragraph twig files.
Brian Canini
committed
*/
function asc_bootstrap_preprocess_paragraph(&$variables) {
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$node = \Drupal::routeMatch()->getParameter('node');
$variables['page_content_type'] = $node->getType();
}
Brian Canini
committed
}
function asc_bootstrap_preprocess_block(&$vars) {
$vars['site_mail'] = \Drupal::config('system.site')->get('mail');
$vars['site_name'] = \Drupal::config('system.site')->get('name');
}
Brian Canini
committed
/*
* 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) {
/*
* events and news filters
*/
if (
($form['#id'] == 'views-exposed-form-events-page-1')
|| ($form['#id'] == 'views-exposed-form-news-page-1')
|| ($form['#id'] == 'views-exposed-form-gallery-directory-page-1')
Brian Canini
committed
/*
* 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(
Brian Canini
committed
'#markup' => '<h2 class="filter-heading">Filter</h2>',
Brian Canini
committed
'#weight' => -10,
);
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
Brian Canini
committed
'#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['end_date']['#weight'] = 1;
Brian Canini
committed
$form['field_evt_taxonomy_target_id_1']['#weight'] = 2;
Brian Canini
committed
$form['field_news_terms_1_target_id']['#weight'] = 2.5;
$form['field_evt_taxonomy2_target_id']['#weight'] = 3;
Brian Canini
committed
$form['field_news_terms_2_target_id']['#weight'] = 3.5;
$form['title']['#weight'] = 5;
$form['title']['#attributes']['placeholder'] = t('Search Keywords');
/*
* research filters
*/
if (
($form['#id'] == 'views-exposed-form-research-project-directory-page-1')
|| ($form['#id'] == 'views-exposed-form-research-project-gallery-page-1')
|| ($form['#id'] == 'views-exposed-form-research-project-directory-mobile-page-1')
|| ($form['#id'] == 'views-exposed-form-research-project-directory-block-1')
|| ($form['#id'] == 'views-exposed-form-research-project-gallery-block-1')
|| ($form['#id'] == 'views-exposed-form-research-project-directory-mobile-block-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' => '<h2 class="filter-heading">Filter</h2>',
'#weight' => -10,
);
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
$form['spacer'] = array(
'#markup' => '<div class="filter-spacer"></div>',
'#weight' => 1.5,
);
/*
* setting up weights for form elements
*/
$form['title']['#weight'] = 5;
$form['title']['#attributes']['placeholder'] = t('Search Keywords');
Brian Canini
committed
/*
* checking if taxonomy has vocabulary - if not, don't display field
*/
//courses
if ($form['#id'] == 'views-exposed-form-courses-page-2') {
/*
* add new HTML content to filters (headers and spacer)
* and setting weights for where they should appear in the form hierarchy
*/
if((count($form['field_course_term_1_target_id']['#options']) > 1)
|| (count($form['field_course_term_2_target_id']['#options']) > 1)
|| (count($form['field_course_term_3_target_id']['#options']) > 1)) {
$form['filter_heading'] = array(
'#markup' => '<h2 class="filter-heading">Filter</h2>',
'#weight' => -10,
);
}
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
'#weight' => 4,
);
$form['spacer'] = array(
'#markup' => '<div class="filter-spacer"></div>',
'#weight' => 1.5,
);
/*
* setting up weights for form elements
*/
$form['title']['#weight'] = 5;
$form['title']['#attributes']['placeholder'] = t('Search Keywords');
if(count($form['field_course_term_1_target_id']['#options']) == 1) {
$form['field_course_term_1_target_id']['#access'] = FALSE;
}
if(count($form['field_course_term_2_target_id']['#options']) == 1) {
$form['field_course_term_2_target_id']['#access'] = FALSE;
}
if(count($form['field_course_term_3_target_id']['#options']) == 1) {
$form['field_course_term_3_target_id']['#access'] = FALSE;
}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
if(isset($form['field_course_term_1_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_1_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_1_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_course_term_2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_2_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_course_term_3_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_3_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_3_target_id']['#options']['All'] = $vocab_label;
}
}
}
}
//courses mobile
if ($form['#id'] == 'views-exposed-form-courses-page-3') {
if((count($form['field_course_term_1_target_id']['#options']) > 1)
|| (count($form['field_course_term_2_target_id']['#options']) > 1)
|| (count($form['field_course_term_3_target_id']['#options']) > 1)) {
$form['filter_heading'] = array(
'#markup' => '<h2 class="filter-heading">Filter</h2>',
'#weight' => -10,
);
}
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
'#weight' => 4,
);
$form['spacer'] = array(
'#markup' => '<div class="filter-spacer"></div>',
'#weight' => 1.5,
);
/*
* setting up weights for form elements
*/
$form['title']['#weight'] = 5;
$form['title']['#attributes']['placeholder'] = t('Search Keywords');
if(count($form['field_course_term_1_target_id']['#options']) == 1) {
$form['field_course_term_1_target_id']['#access'] = FALSE;
}
if(count($form['field_course_term_2_target_id']['#options']) == 1) {
$form['field_course_term_2_target_id']['#access'] = FALSE;
}
if(count($form['field_course_term_3_target_id']['#options']) == 1) {
$form['field_course_term_3_target_id']['#access'] = FALSE;
}
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
if(isset($form['field_course_term_1_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_1_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_1_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_course_term_2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_2_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_course_term_3_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_course_term_3_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_course_term_3_target_id']['#options']['All'] = $vocab_label;
}
}
}
//events
if ($form['#id'] == 'views-exposed-form-events-page-1') {
Brian Canini
committed
if(count($form['field_evt_taxonomy_target_id_1']['#options']) == 1) {
$form['field_evt_taxonomy_target_id_1']['#access'] = FALSE;
}
Brian Canini
committed
if(count($form['field_evt_taxonomy2_target_id']['#options']) == 1) {
$form['field_evt_taxonomy2_target_id']['#access'] = FALSE;
}
Brian Canini
committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
if(isset($form['field_evt_taxonomy_target_id_1']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_evt_taxonomy_target_id_1']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_evt_taxonomy_target_id_1']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_evt_taxonomy2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_evt_taxonomy2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_evt_taxonomy2_target_id']['#options']['All'] = $vocab_label;
}
}
}
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
//gallery
if ($form['#id'] == 'views-exposed-form-gallery-directory-page-1') {
if(count($form['field_gallery_terms_1_target_id']['#options']) == 1) {
$form['field_gallery_terms_1_target_id']['#access'] = FALSE;
}
if(count($form['field_gallery_terms_2_target_id']['#options']) == 1) {
$form['field_gallery_terms_2_target_id']['#access'] = FALSE;
}
if(count($form['field_gallery_terms_3_target_id']['#options']) == 1) {
$form['field_gallery_terms_3_target_id']['#access'] = FALSE;
}
if(isset($form['field_gallery_terms_1_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_gallery_terms_1_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_gallery_terms_1_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_gallery_terms_2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_gallery_terms_2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_gallery_terms_2_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_gallery_terms_3_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_gallery_terms_3_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_gallery_terms_3_target_id']['#options']['All'] = $vocab_label;
}
}
}
}
//news
if ($form['#id'] == 'views-exposed-form-news-page-1') {
Brian Canini
committed
if(count($form['field_news_terms_1_target_id']['#options']) == 1) {
$form['field_news_terms_1_target_id']['#access'] = FALSE;
}
Brian Canini
committed
if(count($form['field_news_terms_2_target_id']['#options']) == 1) {
$form['field_news_terms_2_target_id']['#access'] = FALSE;
Brian Canini
committed
}
Brian Canini
committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
if(isset($form['field_news_terms_1_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_news_terms_1_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_news_terms_1_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_news_terms_2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_news_terms_2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_news_terms_2_target_id']['#options']['All'] = $vocab_label;
}
}
}
//research filters
if (
($form['#id'] == 'views-exposed-form-research-project-directory-block-1')
|| ($form['#id'] == 'views-exposed-form-research-project-directory-page-1')
|| ($form['#id'] == 'views-exposed-form-research-project-gallery-block-1')
|| ($form['#id'] == 'views-exposed-form-research-project-gallery-page-1')
) {
if(count($form['field_research_departments_target_id']['#options']) == 1) {
$form['field_research_departments_target_id']['#access'] = FALSE;
}
if(count($form['field_research_other_target_id']['#options']) == 1) {
$form['field_research_other_target_id']['#access'] = FALSE;
}
if(count($form['field_research_year_target_id']['#options']) == 1) {
$form['field_research_year_target_id']['#access'] = FALSE;
}
if(isset($form['field_research_departments_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_departments_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_departments_target_id']['#options']['All'] = $vocab_label;
}
}
if(isset($form['field_research_other_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_other_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_other_target_id']['#options']['All'] = $vocab_label;
}
}
if(isset($form['field_research_year_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_year_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_year_target_id']['#options']['All'] = $vocab_label;
}
}
Brian Canini
committed
}
//research - mobile
if (($form['#id'] == 'views-exposed-form-research-project-directory-mobile-block-1')||($form['#id'] == 'views-exposed-form-research-project-directory-mobile-page-1')) {
if(count($form['field_research_departments_target_id']['#options']) == 0) {
$form['field_research_departments_target_id']['#access'] = FALSE;
}
if(count($form['field_research_other_target_id']['#options']) == 0) {
$form['field_research_other_target_id']['#access'] = FALSE;
}
if(count($form['field_research_year_target_id']['#options']) == 0) {
$form['field_research_year_target_id']['#access'] = FALSE;
}
if($form['field_research_departments_target_id']['#theme_wrappers']['details']['#title'] == 'Departments') {
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
$tarr = array_slice(array_keys($form['field_research_departments_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_departments_target_id']['#theme_wrappers']['details']['#title'] = $vocab_label;
}
}
}
if($form['field_research_other_target_id']['#theme_wrappers']['details']['#title'] == 'Other') {
$tarr = array_slice(array_keys($form['field_research_other_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_other_target_id']['#theme_wrappers']['details']['#title'] = $vocab_label;
}
}
}
if($form['field_research_year_target_id']['#theme_wrappers']['details']['#title'] == 'Year') {
$tarr = array_slice(array_keys($form['field_research_year_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_year_target_id']['#theme_wrappers']['details']['#title'] = $vocab_label;
}
}
}
}
/*
* research gallery filters
*/
if (($form['#id'] == 'views-exposed-form-research-project-gallery-block-1')||($form['#id'] == 'views-exposed-form-research-project-gallery-page-1')) {
if(count($form['field_research_gallery_tags_target_id']['#options']) == 1) {
$form['field_research_gallery_tags_target_id']['#access'] = FALSE;
}
if(count($form['field_research_gallery_tags_2_target_id']['#options']) == 1) {
$form['field_research_gallery_tags_2_target_id']['#access'] = FALSE;
}
if(count($form['field_research_gallery_tags_3_target_id']['#options']) == 1) {
$form['field_research_gallery_tags_3_target_id']['#access'] = FALSE;
}
if(isset($form['field_research_gallery_tags_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_gallery_tags_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_gallery_tags_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_research_gallery_tags_2_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_gallery_tags_2_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_gallery_tags_2_target_id']['#options']['All'] = $vocab_label;
}
}
}
if(isset($form['field_research_gallery_tags_3_target_id']['#options']['All'])) {
$tarr = array_slice(array_keys($form['field_research_gallery_tags_3_target_id']['#options']), 1, 5, true);
$tid = array_shift($tarr);
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_gallery_tags_3_target_id']['#options']['All'] = $vocab_label;
}
}
}
}
Brian Canini
committed
/*
* people filters
*/
if($form['#id'] == 'views-exposed-form-people-directory-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' => '<h2 class="filter-heading">Filter</h2>',
'#weight' => -10,
);
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
'#weight' => 4,
);
$form['spacer'] = array(
'#markup' => '<div class="filter-spacer"></div>',
'#weight' => 1.5,
);
/*
* setting up weights for form elements
*/
$form['field_appointment_target_id']['#weight'] = 1;
$form['field_research_interests_target_id']['#weight'] = 2;
$form['field_other_target_id']['#weight'] = 3;
$form['combine']['#weight'] = 5;
$form['keys']['#attributes']['placeholder'] = t('Search Keywords');
Brian Canini
committed
/*
* checking if taxonomy has vocabulary - if not, don't display field
*/
if(count($form['field_appointment_target_id']['#options']) == 0) {
$form['field_appointment_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_appointment_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_appointment_target_id_collapsible']['#title'] = $vocab_label;
if(count($form['field_research_interests_target_id']['#options']) == 0) {
$form['field_research_interests_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_research_interests_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_interests_target_id_collapsible']['#title'] = $vocab_label;
if(count($form['field_other_target_id']['#options']) == 0) {
$form['field_other_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_other_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_other_target_id_collapsible']['#title'] = $vocab_label;
}
}
}
}
Brian Canini
committed
/*
* mobile people filters
*/
if($form['#id'] == 'views-exposed-form-people-directory-page-2') {
/*
* 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(
Brian Canini
committed
'#markup' => '<h2 class="ppl-filter-heading ppl-taxon-heading">Filter</h2>',
Brian Canini
committed
);
$form['filter_search_heading'] = array(
'#markup' => '<div class="filter-linebreak"></div>',
Brian Canini
committed
);
/*
* setting up weights for form elements
*/
$form['combine']['#weight'] = 1;
$form['field_appointment_target_id_collapsible']['#weight'] = 3;
$form['field_research_interests_target_id_collapsible']['#weight'] = 4;
$form['field_other_target_id_collapsible']['#weight'] = 5;
if(count($form['field_appointment_target_id']['#options']) == 0) {
$form['field_appointment_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_appointment_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_appointment_target_id_collapsible']['#title'] = $vocab_label;
}
}
if(count($form['field_research_interests_target_id']['#options']) == 0) {
$form['field_research_interests_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_research_interests_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_research_interests_target_id_collapsible']['#title'] = $vocab_label;
}
}
if(count($form['field_other_target_id']['#options']) == 0) {
$form['field_other_target_id_collapsible']['#access'] = FALSE;
}
else {
$tid = array_shift(array_keys($form['field_other_target_id']['#options']));
$term = Term::load($tid);
if (!empty($term)) {
$vid = array_shift($term->vid->getValue())['target_id'];
if(!empty($vid)) {
$vocab = Vocabulary::load($vid);
$vocab_label = $vocab->get('name');
$form['field_other_target_id_collapsible']['#title'] = $vocab_label;
}
}
}
function asc_bootstrap_views_pre_render(\Drupal\views\ViewExecutable $view) {
// print " - view_current_display: " . $view->current_display;
if($view->id() == 'research_project_directory' || $view->id() == 'research_project_directory_mobile') {
$view->element['#cache']['max-age'] = 0;
// get vocabulary name and set label to it
$vocab_dep = Vocabulary::load('departments');
$vocab_dep_label = $vocab_dep->get('name');
$vocab_year = Vocabulary::load('year');
$vocab_year_label = $vocab_year->get('name');
$vocab_other = Vocabulary::load('other');
$vocab_other_label = $vocab_other->get('name');
$view->field['field_research_departments']->options['label'] = $vocab_dep_label;
$view->field['field_research_year']->options['label'] = $vocab_year_label;
$view->field['field_research_other']->options['label'] = $vocab_other_label;
}
}
/*
* views
*/
function asc_bootstrap_preprocess_views_view(&$vars) {
//adds view name variable which is used to identify which view directory user is on (based off view id)
$vars['view_name'] = $vars['id'];
}