drupal tag filter ajax content
<?php
/**
* @file
* Module file for Popolo Custom.
*/
/**
* Implements hook_form_alter().
*/
function popolo_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
// Apply the form_alter to a specific form #id
// the form #id can be found through inspecting the markup.
if($form['#id'] == 'views-exposed-form-filter-articles-page-1') {
// Include js and css, which was defined in libraries.yml.
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.enable';
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.forms';
// Extract the options from the Views Exposed Filter <select>-list.
$links = $form['field_tags_target_id']['#options'];
// Iterate over the options ($links) to build an array ($pop_array) of links.
$i = 0; // Initiate counter/index
$pop_array = array();
foreach ($links as $tid => $term_name) {
if ($tid == 'All') {
$pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" class="active" id="' . $tid . '">' . $term_name . '</a></span>';
}
else {
$pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" id="' . $tid . '">' . $term_name . '</a></span>';
}
$i++; // Increase counter/index
}
// Create the item-list the form should render.
$form['links'] = [
'#theme' => 'item_list',
'#items' => $pop_array,
'#attributes' => ['class' => ['pop-list']],
];
}
}