Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Thank You for great module Facets!
I use it in own project, during setup found: When any facet displayed on homepage "is-active" css class disappeared from "Main navigation" (main) menu "Home" link. How to reproduce:
- Add "Main navigation" menu block (with available "Home" link) to display on site main page (if not added yet)
- Install: search_api, facets modules
- Create several nodes for indexing
- Create Search API DB server
- Create Search API index (use Search API DB server created above)
- Setup index for indexing nodes (that was added above) and index it
- Create views page (for example /articles) that use Search API index as data source
- On "Basic site settings" page set /articles as "Default front page"
- Visit site main page:
- Indexed nodes displayed
- "is-active" class available on "Home" link "Main navigation" menu
- Create any facet for Search API index created above
- Add created facet for display on site main page
- Visit site main page:
- Indexed nodes displayed
- Facet displayed
- "is-active" class not appears on "Home" link "Main navigation" menu
Issue is in QueryString URL processor plugin, method buildUrls() code:
$get_params->set('page', $current_page);
This code not check is $current_page
exists and add "page" param to ParameterBag.
Means (in my case):
- User visit main page, URL is: /
$_GET["page"]
param not exists because pagination not used yet$current_page = NULL
because$_GET["page"]
param not exists- Code
$get_params->set('page', $current_page);
add"page" => NULL
to current page request query ParameterBag - In system.module system_js_settings_alter() function Drupal 8 build and set path settings for
drupalSettings.path
(current page path information in JS). In my case it looks like:
baseUrl: "/" currentLanguage: "en" currentPath: "articles" currentPathIsAdmin: false currentQuery: { page: null } isFront: true pathPrefix: "en/" scriptPath: null
- /core/misc/active-link.js file use
drupalSettings.path
for build correct selectors for select currently "active" links and add "is-active" css class to it - Because
drupalSettings.path.currentQuery
contains not existed{ page: null }
param /core/misc/active-link.js build incorrect selectors - From this reason "Home" link is not selected and "is-active" css class not set
Attached patch fix this issue.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2783847-5.patch | 1.06 KB | andypost |
facets_fix_is_active_home_css_class.patch | 580 bytes | Antonnavi |
Comments
Comment #4
andypostLooks that breaks a lot of tests, probably that's wrong
Comment #5
andypostI think this is a proper fix
Comment #8
andypostTesting broken somehow, as example docs only patch in #2783859: Return value of ResultInterface::getChildren() is array
Comment #9
borisson_Tests broke because #2777483: Unmet dependencies in search api, we can probaby fix that the same way as you fixed #2775963: FacetsSerializer views style plugin depends on optional rest module?
Comment #10
andypostYep, it makes sense for tests also
Comment #12
borisson_Committed, thanks.