- Issue created by @fengtan
- π©πͺGermany fisherman90 Dortmund
Tested the Patch from #2 and can confirm it works :)
Updating to facets 2.0.8 broke our facet summary, which uses the processor "Show a summary of how many results were found".
Whenever a user visits our search view without providing a search query, the view shows a maintenance page with this in the logs:
TypeError: Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay::getCount(): Return value must be of type string, none returned in Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay->getCount() (line 460 of /var/www/web/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php).
The problem was introduced in π Automated Drupal 11 compatibility fixes for facets Fixed , specifically by this change from 74103165:
diff --git a/src/Plugin/facets/facet_source/SearchApiDisplay.php b/src/Plugin/facets/facet_source/SearchApiDisplay.php
index d5b7042..7cb65eb 100644
--- a/src/Plugin/facets/facet_source/SearchApiDisplay.php
+++ b/src/Plugin/facets/facet_source/SearchApiDisplay.php
@@ -449,7 +449,7 @@ class SearchApiDisplay extends FacetSourcePluginBase implements SearchApiFacetSo
/**
* {@inheritdoc}
*/
- public function getCount() {
+ public function getCount(): string {
$search_id = $this->getDisplay()->getPluginId();
if ($search_id && !empty($search_id)) {
if ($this->searchApiQueryHelper->getResults($search_id) !== NULL) {
ShowCountProcessor
expects that getCount()
may return NULL
:
// modules/facets_summary/src/Plugin/facets_summary/processor/ShowCountProcessor.php
...
class ShowCountProcessor extends ProcessorPluginBase implements BuildProcessorInterface {
...
public function build(FacetsSummaryInterface $facets_summary, array $build, array $facets) {
...
$count = $facets_summary->getFacetSource()->getCount();
$build_count = [
'#theme' => 'facets_summary_count',
'#count' => $count === NULL ? 0 : $count,
];
...
}
}
And as a result fails with a TypeError
when that is the case.
Reverting the change on src/Plugin/facets/facet_source/SearchApiDisplay.php
above fixes the issue, but my understanding is that providing a type declaration for the function's return value is required for Drupal 11.
Attached is a suggested patch that turns the return type from string
to ?string
and also fixes the issue.
Active
2.0
Facet summary
Tested the Patch from #2 and can confirm it works :)