drupal tag filter ajax content code example
Example: drupal tag filter ajax content
<?php
function popolo_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
if($form['#id'] == 'views-exposed-form-filter-articles-page-1') {
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.enable';
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.forms';
$links = $form['field_tags_target_id']['#options'];
$i = 0;
$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++;
}
$form['links'] = [
'#theme' => 'item_list',
'#items' => $pop_array,
'#attributes' => ['class' => ['pop-list']],
];
}
}