Problem/Motivation

Seeing these errors on views page.

  • Notice: Undefined index: #options in Drupal\Core\Render\Element\Radios::processRadios() (line 62 of core/lib/Drupal/Core/Render/Element/Radios.php).
  • Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Render\Element\Radios::processRadios() (line 62 of core/lib/Drupal/Core/Render/Element/Radios.php).

Steps to reproduce

Occuring on View with views_exposed_form using radio buttons.

Proposed resolution

If options are empty then it throws the warning - so check for empty before referencing the #options array index.

Fulll stack trace is

Notice: Undefined index: #options in Drupal\Core\Render\Element\Radios::processRadios() (line 62 of core/lib/Drupal/Core/Render/Element/Radios.php). 
Drupal\Core\Render\Element\Radios::processRadios(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 1007)
Drupal\Core\Form\FormBuilder->doBuildForm('views_exposed_form', Array, Object) (Line: 1070)
Drupal\Core\Form\FormBuilder->doBuildForm('views_exposed_form', Array, Object) (Line: 574)
Drupal\Core\Form\FormBuilder->processForm('views_exposed_form', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 134)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1238)
Drupal\views\ViewExecutable->build() (Line: 392)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 196)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('sample_view', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

And

Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Render\Element\Radios::processRadios() (line 62 of core/lib/Drupal/Core/Render/Element/Radios.php).

Drupal\Core\Render\Element\Radios::processRadios(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 1007)
Drupal\Core\Form\FormBuilder->doBuildForm('views_exposed_form', Array, Object) (Line: 1070)
Drupal\Core\Form\FormBuilder->doBuildForm('views_exposed_form', Array, Object) (Line: 574)
Drupal\Core\Form\FormBuilder->processForm('views_exposed_form', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 134)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1238)
Drupal\views\ViewExecutable->build() (Line: 392)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 196)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('cpe_catalog_search', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Remaining tasks

Merge fork from Merge request.
I'm not sure how to get this merged : https://git.drupalcode.org/issue/drupal-3298714/-/merge_requests/2

CommentFileSizeAuthor
#6 3298714.patch812 bytesdshumaker

Issue fork drupal-3298714

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 9.4.x Comparecompare
  • 3298714-undefined-options-and Comparecompare
  • 1 hidden branch
  • 9.5.x Comparechanges, plain diff MR !2527

Comments

dshumaker created an issue. See original summary.

dshumaker’s picture

Issue summary: View changes

dshumaker’s picture

Issue summary: View changes
dshumaker’s picture

StatusFileSize
new812 bytes

Couldn't figure out the confusing new fork/patch/merge request interface so I'm attaching a patch of the MR.

https://git.drupalcode.org/issue/drupal-3298714/-/merge_requests/2/diffs

dshumaker’s picture

I’m not exactly sure but like those other referenced issues the warnings only showed up after upgrades to drupal 9.4 and php7.4.

And its less of a work around than a safeguard. If for any reason there are no options then we don’t fail. The other issues were solved in a similar fashion.

karimbou’s picture

Having this issue on Drupal 9.4.5 - 9.4.8 when we switched from PHP 7.4 to PHP 8.1

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aaronchristian’s picture

Confirmed this is still an issue in 10.0.9 when configuring your view settings.

After applying the patch, started receiving a 500 error on the page unfortunately.

Error from the logs;

TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 62 of /var/www/docroot/core/lib/Drupal/Core/Render/Element/Radios.php).

kenorb’s picture