1<?php
2
3/**
4 * @file
5 * Module file for Popolo Custom.
6 */
7
8/**
9 * Implements hook_form_alter().
10 */
11function popolo_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
12
13 // Apply the form_alter to a specific form #id
14 // the form #id can be found through inspecting the markup.
15 if($form['#id'] == 'views-exposed-form-filter-articles-page-1') {
16
17 // Include js and css, which was defined in libraries.yml.
18 $form['#attached']['library'][] = 'popolo_custom/popolo_custom.enable';
19 $form['#attached']['library'][] = 'popolo_custom/popolo_custom.forms';
20
21 // Extract the options from the Views Exposed Filter <select>-list.
22 $links = $form['field_tags_target_id']['#options'];
23
24 // Iterate over the options ($links) to build an array ($pop_array) of links.
25 $i = 0; // Initiate counter/index
26 $pop_array = array();
27 foreach ($links as $tid => $term_name) {
28 if ($tid == 'All') {
29 $pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" class="active" id="' . $tid . '">' . $term_name . '</a></span>';
30 }
31 else {
32 $pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" id="' . $tid . '">' . $term_name . '</a></span>';
33 }
34 $i++; // Increase counter/index
35 }
36
37 // Create the item-list the form should render.
38 $form['links'] = [
39 '#theme' => 'item_list',
40 '#items' => $pop_array,
41 '#attributes' => ['class' => ['pop-list']],
42 ];
43 }
44}
45