Problem/Motivation
Using a date field on a search api view using a group filter with the between operator does not filter and shows and error in drupal log.
It does not happend if use the same filter on a normal view, so the problem seems to be related with both modules, date and search api.
It worked on 8.7 version but we updated the core to 8.8 and started to fail.
Steps to reproduce
- Install search api
- Index a date field
- Create a search api view
- Add some group exposed filters with the operator between
- Choose the option "An offset from the current time such as" in the filter
- Fill min with "-1 year" and max with "+1" year, "-2 years" "-1 year" ...
- Try to filter by those options
Documentation
Here is the error:
Warning: Illegal string offset 'max' en Drupal\views\Plugin\views\filter\Date->acceptExposedInput() (línea 160 de /var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php)
#0 /var/www/html/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'Illegal string ...', '/var/www/html/w...', 160, Array)
#1 /var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php(160): _drupal_error_handler(2, 'Illegal string ...', '/var/www/html/w...', 160, Array)
#2 /var/www/html/web/modules/contrib/search_api/src/Plugin/views/filter/SearchApiDate.php(81): Drupal\views\Plugin\views\filter\Date->acceptExposedInput(Array)
#3 /var/www/html/web/core/modules/views/src/Form/ViewsExposedForm.php(192): Drupal\search_api\Plugin\views\filter\SearchApiDate->acceptExposedInput(Array)
#4 [internal function]: Drupal\views\Form\ViewsExposedForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(112): call_user_func_array(Array, Array)
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(591): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('views_exposed_f...', Array, Object(Drupal\Core\Form\FormState))
#9 /var/www/html/web/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php(134): Drupal\Core\Form\FormBuilder->buildForm('\\Drupal\\views\\F...', Object(Drupal\Core\Form\FormState))
#10 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1238): Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm()
#11 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1391): Drupal\views\ViewExecutable->build(NULL)
#12 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1454): Drupal\views\ViewExecutable->execute(NULL)
#13 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2438): Drupal\views\ViewExecutable->render()
#14 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1662): Drupal\views\Plugin\views\display\DisplayPluginBase->preview()
#15 /var/www/html/web/core/modules/views_ui/src/ViewUI.php(605): Drupal\views\ViewExecutable->preview('page', Array)
#16 /var/www/html/web/core/modules/views_ui/src/ViewPreviewForm.php(62): Drupal\views_ui\ViewUI->renderPreview('page', Array)
#17 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityForm.php(149): Drupal\views_ui\ViewPreviewForm->form(Array, Object(Drupal\Core\Form\FormState))
#18 /var/www/html/web/core/modules/views_ui/src/ViewFormBase.php(41): Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#19 [internal function]: Drupal\views_ui\ViewFormBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'page')
#20 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(520): call_user_func_array(Array, Array)
#21 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(370): Drupal\Core\Form\FormBuilder->retrieveForm('view_preview_fo...', Object(Drupal\Core\Form\FormState))
#22 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(627): Drupal\Core\Form\FormBuilder->rebuildForm('view_preview_fo...', Object(Drupal\Core\Form\FormState), Array)
#23 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('view_preview_fo...', Array, Object(Drupal\Core\Form\FormState))
#24 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(91): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\views_ui\ViewPreviewForm), Object(Drupal\Core\Form\FormState))
#25 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#26 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#27 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#28 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#29 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#30 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#31 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#41 {main}
Duplicated information from core issue: https://www.drupal.org/project/drupal/issues/3111379
Comments
Comment #2
drunken monkeySorry, I can’t reproduce this, it works fine for me:
I’m using the latest Search API version and Drupal 8.9 HEAD (
ea742ff0254f).Comment #3
bbu23I think it might be related to this issue. I am having problems with this atm, but I am not sure if it's the same problem. I created a grouped filter for a taxonomy field. https://www.drupal.org/project/drupal/issues/1810148
Comment #4
liquidcms commentedEduardo posted this here and against core.. and i have been commenting on the core issue.. when it likely is more of a searchapi issue.
my latest findings:
a lot more testing on this and here is what i see:
- i have tried this on 2 sites now: large and small: small is basically a basic D8 install with searchapi and no solr, large has many modules including searchapi and solr
on the large site:
- grouped views on date field with "is between" fails when using searchapi; but not when using std content view
- this fails on core 8.8 and 8.9; not able to test with 8.7
- other filters grouped filter operators like "is equal to" work with searchapi
on small site:
- with 8.8 and 8.9 this works with searchapi
so my guess is that this is not a core issue. sounds like maybe a searchapi issue; but odd that it works on 1 site but not the other.
I also do not see any warnings like posted above. I do see a bunch of notices for undefined indexes related to views, and date.
I'll try to debug.
ALSO, i see bbu23's issue, grouped with taxonomy also does not work (my large site); need to check on small site.
Can't say 100% that this is a searchapi issue as it does work on small site; but it does fail with searchapi only on large site.
Comment #5
liquidcms commentedthe issue seems to be this code that is in SearchApiDate.php
It mentions this issue on core: #2704077: Exposed operator for Views date filters doesn't accept "(not) empty", which although it is "Needs Review" state and i dont see that it has been committed; it is in my code (8.9.9) and the patch part is also on my small site (currently at 8.8.8) but the code within the elseif is different.
anyway, if i remove that entire section; my date filter works as expected.
But, guessing breaks something else.
Comment #6
liquidcms commentedHere is a patch for removing the above code.
Comment #7
liquidcms commentedComment #8
drunken monkeyYou’re right, that issue has long ago been fixed. Thanks a lot for noticing that and posting it here!
Then, yes, we can just remove that workaround now, especially if it causes problems in some situations (even if we can’t say for sure when or why).
So: committed. Thanks again!