Problem/Motivation
The $granularity variable at line 78 of src/Plugin/facets/query_type/SearchApiDate.php is being recalculated based on $value instead of being assigned the Granularity configured at admin/config/search/facets/authored/edit . If $value is in format YYYY-MM-DD, then the recalculated $granularity will not match the admin page Granularity configuration.
Steps to reproduce
* admin/config/search/facets/authored/edit
* Set "Date item processor settings" > "Date display" to "Relative date"
** Set "Date item processor settings" > "Granularity" to "Month"
** Navigate to Search Results page
** RESULT: The facet will display "...months ago..." correctly, but clicking on one of the facet links will return no search results and a "The date cannot be created from a format." error. Checking the value of $granularity at the location described above reveals that it is 4 (FACETAPI_DATE_DAY) instead of 5 (FACETAPI_DATE_MONTH).
Proposed resolution
Recalculating $granularity is unnecessary since $granularity can already be assigned as $this->getGranularity();.
Remaining tasks
Creating patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3277819-calculaterange-granularity.patch | 719 bytes | ronaldmulero |
Comments
Comment #2
ronaldmulero commentedHere's the patch.
facets 2.0.x
Drupal 9.3.12
Comment #3
mkalkbrennerI tested the patch manually. At least facets with absolute date ranges fail if this patch is applied.
Maye we need to distinguish between the absolute and relative date range.
Obviously we don't have enough test coverage here.