Problem/Motivation
Since Facets 3.0.4, facets_preprocess_facets_item_list() — and the equivalent preprocess functions in the facets_summary and facets_searchbox_widget submodules — call:
\Drupal::service(ThemePreprocess::class)->preprocessItemList($variables);Drupal\Core\Theme\ThemePreprocess is a core service/class that only exists in Drupal 11 (added as part of the OOP conversion of template_preprocess_* functions, see core issue #3504381). It does not exist in Drupal 10.x.
facets.composer.json still only requires drupal/core: <10.1.0 as a floor, so the module installs cleanly on Drupal 10 but fatals at render time on any page that renders a facets item list.
Note that DeprecationHelper::backwardsCompatibleCall() is already used elsewhere in facets.module for exactly this kind of core-version compatibility — it just wasn't applied to these 4 new ThemePreprocess call sites, which looks like an oversight in the 3.0.4 release.
Steps to reproduce
- Install Facets 3.0.4 on a site running Drupal core 10.x (e.g. 10.6.15).
- Visit any page that renders a facets item list (e.g. a Search API facets block, or a view page with facets enabled).
- Observe a fatal error:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "Drupal\Core\Theme\ThemePreprocess". in Drupal\Component\DependencyInjection\Container->get() (line 159 of core/lib/Drupal/Component/DependencyInjection/Container.php). Drupal::service() (Line: 233) facets_preprocess_facets_item_list()
Proposed resolution
Guard each ThemePreprocess::class call with class_exists(), falling back to core's procedural template_preprocess_item_list() (still present in Drupal 10) when the class isn't available:
if (class_exists(ThemePreprocess::class)) { \Drupal::service(ThemePreprocess::class)->preprocessItemList($variables); } else { template_preprocess_item_list($variables); }
Patch attached, applied at the following 4 call sites:
facets.module:facets_preprocess_facets_item_list()modules/facets_summary/facets_summary.module:facets_summary_preprocess_facets_summary_item_list()modules/facets_searchbox_widget/facets_searchbox_widget.module:facets_searchbox_widget_preprocess_facets_item_list__searchbox_checkbox()and..._searchbox_links()
Remaining tasks
- Review/apply patch
- Consider whether
facets.info.yml/composer.jsonshould instead gate oncore_version_requirementif the intent was to drop Drupal 10 support in 3.0.4 (unclear from release notes) - Add test coverage rendering a facets item list on Drupal 10 to catch this regression
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | fix-fatal-servicenotfoundexception-3618076-5.patch | 5.73 KB | finn lewis |
Issue fork facets-3618076
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
asamoahboateng commentedComment #4
timwoodSeems like the same issue reported in https://www.drupal.org/project/facets/issues/3605291. Not sure which to keep.
Comment #5
timwoodThe MR patch here seems to resolve the error.
Comment #6
finn lewisThanks for all the work on this folks!
I can also confirm this works for me on Drupal 10.6.14 with Facets 3.0.4, using the patch from the merge request https://git.drupalcode.org/project/facets/-/merge_requests/396
I'm attaching a patch file for this, just to help our composer install until we can get a release.
Any chance we could get this merged and released soon or is there a different approach that would be better for Drupal 10?
Many thanks,
Finn
Comment #7
awearring commentedThe MR/patch resolves the issue for me.
+1 for a quick release
Comment #8
joeswarbs commentedDitto ^^^ Patch fixed the same issue for me too.
Comment #9
chrisgibson commentedI can confirm that the patch above fixed the issue for me.
Comment #10
joelpittetDitto, changing the issue to the dev version as that is where this will be applied and fixed for the next release. #3594309: Broken/missing handler after update to Facets 3.0.4: Restore facets_exposed_filters.module file and use LegacyHook for Drupal 10 will be needed as well.
Comment #11
joelpittetThis seems like a duplicate of #3605291: facets_preprocess_facets_item_list() is broken in Drupal 11.2 and older which is older, tempted to close this in favour of that.
Comment #12
joelpittetLets focus on #3605291: facets_preprocess_facets_item_list() is broken in Drupal 11.2 and older and #3594309: Broken/missing handler after update to Facets 3.0.4: Restore facets_exposed_filters.module file and use LegacyHook for Drupal 10. Closing this as a duplicate. The other issues are older and have a slightly more appropriate fix.
It's nice to have test coverage but I am not totally sure if that is really needed in this case...