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?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source