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']],
];
}
}
Are there any code examples left?
New code examples in category Javascript
-
Javascript 2023-04-21 22:52:36
-
Javascript 2022-03-27 22:25:20 javascript download string as file
-
Javascript 2022-03-27 21:40:22 sort numbers in array javascript
-
Javascript 2022-03-27 21:20:04 compare two arrays and return the difference javascript
-
Javascript 2022-03-27 21:15:02 javascript regex french phone number
-
Javascript 2022-03-27 21:05:03 cypress custom error message
-
Javascript 2022-03-27 21:00:05 create element javascript with id
-
Javascript 2022-03-27 20:40:57 feather icons react
-
Javascript 2022-03-27 20:20:01 how to make graphql request in axios
-
Javascript 2022-03-27 20:15:07 bootstrap validator password and confirm password