- Issue created by @sumeet-biswal
- Status changed to Postponed: needs info
almost 2 years ago 12:08pm 9 February 2023 We get defensive patches like this a lot. But to have it merged we need steps to reproduce and an understanding of the root cause.
- 🇺🇸United States alfattal Minnesota
I had the same issue with a view that has an exposed boolean filter. The patch in #2 fixed the issue for me. Here is a full trace for the error message:
Warning: Trying to access array offset on value of type bool in Drupal\views\Plugin\views\PluginBase->setOptionDefaults() (line 187 of core/modules/views/src/Plugin/views/PluginBase.php). Drupal\views\Plugin\views\PluginBase->setOptionDefaults(Array, Array) (Line: 141) Drupal\views\Plugin\views\PluginBase->init(Object, Object, Array) (Line: 104) Drupal\views\Plugin\views\HandlerBase->init(Object, Object, Array) (Line: 95) Drupal\views\Plugin\views\filter\FilterPluginBase->init(Object, Object, Array) (Line: 894) Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('filter') (Line: 1045) Drupal\views\ViewExecutable->_initHandler('filter', Array) (Line: 903) Drupal\views\ViewExecutable->initHandlers() (Line: 2318) Drupal\views\Plugin\views\display\DisplayPluginBase->preExecute() (Line: 1697) Drupal\views\ViewExecutable->preExecute(Array) (Line: 1632) Drupal\views\ViewExecutable->executeDisplay('vita_search_block', Array) (Line: 81) Drupal\views\Element\View::preRenderViewElement(Array) (Line: 59) Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 106) Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object) call_user_func(Array, Object, 'section_component.build.render_array', Object) (Line: 142) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'section_component.build.render_array') (Line: 90) Drupal\layout_builder\SectionComponent->toRenderArray(Array, ) (Line: 88) Drupal\layout_builder\Section->toRenderArray(Array) (Line: 316) Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Object) (Line: 275) Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 340) Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24) Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282) Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239) Drupal\Core\Entity\EntityViewBuilder->build(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: 788) Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374) Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204) Drupal\Core\Render\Renderer->render(Array, ) (Line: 242) Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243) 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: 174) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 68) Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 50) Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 270) Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 137) Drupal\shield\ShieldMiddleware->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: 718) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
It worth mentioning the issue didn't break the views functionality as it was still returning results as expected.
- Status changed to Needs review
over 1 year ago 8:54pm 1 June 2023 - 🇨🇦Canada rbrownell Ottawa, Ontario, Canada
This is a very difficult issue to reproduce as it relies on a views plugin improperly defining one or more options.
Prior to Drupal 9.5, Views did not expect every options value to be an associative array. This particular error occurs when an option is defined in a Views plugin that has a Boolean value without being nested within an associative array with an item with the key
default
.For example, in the most recent version of the Search API Location Views module (8.x-1.0-alpha3) an option with key
require
is defined within thedefineOptions()
function as:$options['require'] = FALSE;
This does not follow the prescribed structure found in the PluginBase parent class which reads:
/** * Information about options for all kinds of purposes will be held here. * @code * 'option_name' => array( * - 'default' => default value, * - 'contains' => (optional) array of items this contains, with its own * defaults, etc. If contains is set, the default will be ignored and * assumed to be array(). * ), * @endcode * * @return array * Returns the options of this handler/plugin. */ protected function defineOptions() {
In the example above the correct way of implementing this option is:
$options['require'] = ['default' = FALSE];
As a result of this, in order to resolve this situation, updates to the output of the offending Views plugin's
defineOptions()
functions should be made to follow the prescribed array structure instead of updating Drupal core.Recommend changing issue status to Closed (won't fix).
- Status changed to Needs work
over 1 year ago 9:41pm 1 June 2023 - 🇺🇸United States smustgrave
Think it should be investigated why it is sometimes a boolean, don't want to put a patch over a larger problem.
The step "Create a views plugin that does not implement the correct options array structure." makes me think it was a user error.
As a bug will need test case showing the issue.