Update behaviour of newsroom so users are not sent off to another page.

Drupal 10
LGD

I’ve faced numerous requests from clients to update newsroom behavior so filtering is happening on the same page rather than sending to another page. Here is a quick guide to achieve this.

  1. Install and enable Facets Block module. https://www.drupal.org/project/facets_block
    1. composer require 'drupal/facets_block:^2.0'
  2. Edit News search view:
    1. Add block display. 
    2. Exposed form in block - Yes
    3. Use AJAX - Yes
    4. Disable page display.
  3. Add Views reference field to Newsroom content type to display Views block added in step 2. (We can set the field default value or make it editable). Place it where necessary (Use ‘Manage display tab’ [I would prefer] or a twig template).

  4.  

    Update Facets:  admin/config/search/facets  we should have "Date" facet under Block display (not Page).

 

 

 

5.  Create Facet block. I put it under “Disabled” region and placed it as an Extra field to adjust the layout as needed for theming, but could be anywhere.

 

6. Place exposed form (step 2 b). Same here - I put it under the disabled region and display in “Manage display” section using the Extra field.

7. I’ve also found that facets don’t always work with AJAX correctly, especially for views added as a paragraph, but patch https://www.drupal.org/files/issues/2023-09-06/facets-with-ajax-not-working-in-most-of-situations-3052574-184.patch solves issue.

"drupal/facets": {
"Facets with AJAX not working in most of situations[Issue when added facet in para]": "https://www.drupal.org/files/issues/2023-09-06/facets-with-ajax-not-working-in-most-of-situations-3052574-184.patch"
},

  

References