Problem/Motivation
There are 2 ways i can see to add a date range end value:
1. add the full Date field and in view select end value as click sort and rewrite field as just the end value.
2. add only the end date to the index and add this in the view
1. does show the end date correctly; but regardless of what is selected for sort; it only uses the start date for sorting
2. causes the view to crash with the error:
InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 198 of E:\www\drupal8\web\core\lib\Drupal\Component\Datetime\DateTimePlus.php).
Steps to reproduce
- default D8 site
- add a date range field to Article bundle
- add end value of this field to search index
- create a view listing indexed end date
running the view gives wsod.
Proposed resolution
As i think SearchAPI/Views cannot sort on rewritten values; i think the correct solution would be to have the End Value field work correctly as a separate indexable value.
Remaining tasks
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3187134-2--views_field_date_range_end.patch | 5.97 KB | drunken monkey |
| #2 | 3187134-2--views_field_date_range_end--tests_only.patch | 4.12 KB | drunken monkey |
Comments
Comment #2
drunken monkeyThanks a lot for reporting this problem.
As you yourself state, though, the real problem here is that displaying end dates in Views leads to a fatal error. Everything else seems to work fine. Adapting the title accordingly.
Anyways, I could easily reproduce the problem, after a bit also found a reasonably clean solution (not exactly perfect, but good enough, I think) and then even managed to write a regression test for the bug.
Please test/review the attached patch and see whether it resolves the problem for you, too.
Comment #4
liquidcms commentedHey dm, thanks for the patch. I ended up doing a few computed fields in my entity to get around the problem that re-written fields can't be sorted. This would have been one of them. Seemed a little hacky; but did the job nicely.
I'll try to test your patch on a generic test site i think i still have set up.
Thanks again.
Comment #5
drunken monkeyDo you still plan on testing this? Would be great to get feedback.
Otherwise, I can either commit and hope for the best or risk losing both our efforts.
Comment #6
liquidcms commentedTested. View no longer crashes; but view is not sortable on the end date field.:
- https://take.ms/O8TRm
- https://take.ms/Ivhw0z
Comment #7
drunken monkeyIt works fine for me. Did you maybe forget to reindex after adding the field?
Otherwise, please tell me the generated search query (if you have Devel installed, adding
dpm((string) $query);at the top of\Drupal\search_api\Entity\Server::search()should suffice) and what backend you are using. If the correct query is generated (and you did reindex), then the backend plugin seems at fault.Comment #9
drunken monkeyCommitted.
Comment #10
liquidcms commentedhey, sorry i didnt get a chance to restest. Unlikely i wouldn't have re-indexed. This was using solr on the real site but drupal db on a test site. Both presented the issue.
I think it is safe to assume if you have fixed issue #2 so that end date can now be indexed; there shouldnt be any reason it wouldn't be sortable in a View. :)
thanks.