When I attempt to rewrite filter text on a filter with non-alphanumeric characters I get an error. I've tried wrapping the value in quotes and escaping the characters.

So far I've attempted to rewrite '- Any -' and '31.5"'. The fields I am attempting to rewrite are List (text).

Warning: Illegal offset type in isset or empty in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions() (line 1131 of modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php).
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions(Array, '31.5"|value') (Line: 754)
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter(Array, Object) (Line: 119)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 512)
Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 147)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1224)
Drupal\views\ViewExecutable->build() (Line: 349)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 167)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1615)
Drupal\views\ViewExecutable->executeDisplay('product_category_televisions', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Notice: Undefined variable: selected in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter() (line 755 of modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php).
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter(Array, Object) (Line: 119)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 512)
Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 147)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1224)
Drupal\views\ViewExecutable->build() (Line: 349)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 167)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1615)
Drupal\views\ViewExecutable->executeDisplay('product_category_televisions', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

chriswinger created an issue. See original summary.

mikeker’s picture

Status: Active » Postponed (maintainer needs more info)

My apologies for the delay getting to this issue. Using the latest BEF and Drupal 8.3.x core, I'm unable to reproduce this. In fact, I just checked in a fix that will let you rewrite the "- Any -" text...

Please reactivate this issue if you're still experiencing it and include the steps to reproduce and an export of the view in question.

Thanks!

sagesolutions’s picture

Status: Postponed (maintainer needs more info) » Needs work

This issue is also happening to me.

I have AJAX enabled on my view I am currently running Drupal 8.2.2.

levmyshkin’s picture

BEF module uses $option to store string and objects (Markup object for -Any- replacement). So we need to check $option variables is string. You can't override -Any- by rewrite field, because -Any- use markup object.
Try to use this patch to get it works. I also add checks for removing PHP notices.

My PHP warnings were:
Warning: Illegal offset type in isset or empty in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions() (line 1131 of modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php).
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions(Array, 'Article|Articles
Chart|Charts
Report|Reports') (Line: 754)
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter(Array, Object) (Line: 120)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 135)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1225)
Drupal\views\ViewExecutable->build() (Line: 351)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 168)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1617)
Drupal\views\ViewExecutable->executeDisplay('blog_all', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Notice: Undefined variable: selected in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter() (line 755 of modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php).
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter(Array, Object) (Line: 120)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 135)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1225)
Drupal\views\ViewExecutable->build() (Line: 351)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 168)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1617)
Drupal\views\ViewExecutable->executeDisplay('blog_all', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

levmyshkin’s picture

StatusFileSize
new1.89 KB

Sorry, the previous file was empty

mikeker’s picture

Status: Needs work » Needs review

Sorry for the delay getting to this -- if there is a possible solution, please mark the issue as needs review so that it gets flagged for the maintainer. Thanks for the patch, I will review it shortly.

mikeker’s picture

Status: Needs review » Closed (duplicate)

I believe this was fixed with this commit back in Aug 2016. Can you try the latest -dev release and let me know if you still see this problem?

Thanks.

levmyshkin’s picture

I installed BEF dev version and Drupal 8.2.5, it works good with replacements.

drupalfan2’s picture

I can not rewrite "- Any -" in latest version and latest dev version (Drupal 8).

Any solution in the meantime?

johnpicozzi’s picture

Hello,

I seem to be having a version of this issue. It seems to be happening when I translate our site into Japaneses. Getting the following error

Notice: Undefined offset: 1 in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions() (line 1342 of /app/docroot/modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php) #0 /app/docroot/core/includes/bootstrap.inc(587): _drupal_error_handler_real(8, 'Undefined offse...', '/app/docroot/mo...', 1342, Array) #1 /app/docroot/modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php(1342): _drupal_error_handler(8, 'Undefined offse...', '/app/docroot/mo...', 1342, Array) #2 /app/docroot/modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php(913): Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->rewriteOptions(Array, '\xC2\xA0') #3 /app/docroot/core/modules/views/src/Form/ViewsExposedForm.php(122): Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter(Array, Object(Drupal\Core\Form\FormState)) #4 [internal function]: Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #5 /app/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(519): call_user_func_array(Array, Array) #6 /app/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(276): Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_f...', Object(Drupal\Core\Form\FormState)) #7 /app/docroot/modules/contrib/views_exposed_filter_blocks/src/Plugin/Block/ViewsExposedFilterBlocksBlock.php(101): Drupal\Core\Form\FormBuilder->buildForm('views_exposed_f...', Object(Drupal\Core\Form\FormState)) #8 /app/docroot/core/modules/block/src/BlockViewBuilder.php(163): Drupal\views_exposed_filter_blocks\Plugin\Block\ViewsExposedFilterBlocksBlock->build() #9 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array) #10 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func('Drupal\\block\\Bl...', Array) #11 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) #12 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render(Array, true) #13 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() #14 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #15 /app/docroot/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain(Array) #16 /app/docroot/core/modules/big_pipe/src/Render/BigPipe.php(693): Drupal\Core\Render\Renderer->renderPlaceholder('callback=Drupal...', Array) #17 /app/docroot/core/modules/big_pipe/src/Render/BigPipe.php(547): Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=Drupal...', Array) #18 /app/docroot/core/modules/big_pipe/src/Render/BigPipe.php(305): Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object(Drupal\Core\Asset\AttachedAssets)) #19 /app/docroot/core/modules/big_pipe/src/Render/BigPipeResponse.php(112): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse)) #20 /app/vendor/symfony/http-foundation/Response.php(374): Drupal\big_pipe\Render\BigPipeResponse->sendContent() #21 /app/docroot/index.php(20): Symfony\Component\HttpFoundation\Response->send() #22 {main}.

After doing some debugging on line 1342 I find that $rewriteSettings and $line are both empty when on the JP site. After reading this issue https://www.drupal.org/project/better_exposed_filters/issues/2950053 and going into the translation settings and populating the translation the error goes away. Seems like we need a check here to prevent this from causing an error.

I also applied this patch but it didn't resolve the issue https://www.drupal.org/project/better_exposed_filters/issues/3007843

johnpicozzi’s picture

Status: Closed (duplicate) » Active
neslee canil pinto’s picture

Status: Active » Closed (won't fix)

We are trying to deprecate 8.x-3.x, can you please check whether this still exists in 8.x-4.x/8.x-5.x branch.

johnpicozzi’s picture

@Neslee Canil Pinto Unfortunately, I will not be able to test this again any time soon. Hopefully, someone else can try to test it based on my comments above.

neslee canil pinto’s picture

@johnpicozzi hopefully this issue is resolved in 8.x-4.x/8.x-5.x which is actively maintained now. Thanks for your confirmation.