Drupal 8/9: Facets AJAX commands

Faceted search

Possible solutions

  • Disable AJAX on the faceted search 💩
  • Listen to the facets_filter JavaScript event 😐
  • Alter the response object of the facet AJAX callback 👍

The JavaScript event

  • Add a JavaScript file
  • Add an event listener
  • Execute (jQuery) AJAX call(s) to the Drupal back-end
  • Update the content with for example jQuery(‘.selector’).html(response);

Altering the response object

/facets-block-ajax
  1. I didn’t need an extra (unnecessary) request to the back-end
  2. I only had to add some PHP code to make this work. Everything simple and centralized, just as I like my code to be.

The best way forward

Overriding the facet route

Adding a custom controller

Defining a custom event

Adding event subscribers

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building your own Retrofit Call Adapter

What is the developpement angular.

How to automate charts (Canvas Element) using Javascript in selenium (without image comparison)

Testing Network Application Functionality

images/message-boundary.png

Typescript Make Some Key Optional

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Robin Ingelbrecht

Robin Ingelbrecht

More from Medium

Nuts & bolts of internationalization and localization with Symfony

PHP — What is OOP?

How to update a mysql column’s data type for an already migrated Table in PHP

A simple PHP site (4/?)— Routing