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

  1. Install Facets 3.0.4 on a site running Drupal core 10.x (e.g. 10.6.15).
  2. Visit any page that renders a facets item list (e.g. a Search API facets block, or a view page with facets enabled).
  3. 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.json should instead gate on core_version_requirement if 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.

Issue fork facets-3618076

Command icon 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

asamoahboateng created an issue. See original summary.

asamoahboateng’s picture

Title: erviceNotFoundException: ... "Drupal\Core\Theme\ThemePreprocess" on Drupal 10 in facets 3.0.4 » Fatal error ServiceNotFoundException: ... "Drupal\Core\Theme\ThemePreprocess" on Drupal 10 in facets 3.0.4

timwood’s picture

Seems like the same issue reported in https://www.drupal.org/project/facets/issues/3605291. Not sure which to keep.

timwood’s picture

Status: Active » Reviewed & tested by the community

The MR patch here seems to resolve the error.

finn lewis’s picture

Thanks 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

awearring’s picture

The MR/patch resolves the issue for me.

+1 for a quick release

joeswarbs’s picture

Ditto ^^^ Patch fixed the same issue for me too.

chrisgibson’s picture

I can confirm that the patch above fixed the issue for me.

joelpittet’s picture

Version: 3.0.4 » 3.0.x-dev

Ditto, 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.

joelpittet’s picture

This 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.

joelpittet’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Lets 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...

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.