Problem/Motivation
Seeing PHP notices related to views
Notice: Trying to access array offset on value of type bool in Drupal\views\Plugin\views\PluginBase->setOptionDefaults() (line 187 of docroot/core/modules/views/src/Plugin/views/PluginBase.php)
Steps to reproduce
Have a view that uses search api location and a location filter
Proposed resolution
Resolve the notice
I believe this is coming from
SearchApiFilterLocation.php
Specifically
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['plugin']['default'] = '';
foreach ($this->locationInputManager->getDefinitions() as $id => $plugin) {
$options["plugin-$id"]['default'] = [];
}
$options['value'] = [
'contains' => [
'value' => ['default' => ''],
'distance' => [
'contains' => [
'from' => ['default' => ''],
'to' => ['default' => ''],
],
],
],
];
$options['require'] = FALSE; <----- problem, I believe
return $options;
}Views, at least in Drupal 9.5 is expecting every options value to be an array.
From PluginBase.php (views)
protected function setOptionDefaults(array &$storage, array $options) {
foreach ($options as $option => $definition) {
if (isset($definition['contains'])) {
$storage[$option] = [];
$this->setOptionDefaults($storage[$option], $definition['contains']);
}
else {
$storage[$option] = $definition['default']; <----- where the notice is firing
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | php-notice-views-default-3343143-3.patch | 608 bytes | aaron.ferris |
Comments
Comment #2
aaron.ferris commentedComment #3
aaron.ferris commentedComment #4
aaron.ferris commentedComment #5
aaron.ferris commentedComment #6
progga commentedI can confirm that the patch from #3 works for me. Thanks a lot for the fix :)
Comment #7
progga commentedAdditionally, this new `require` option introduced in #3070519 is missing a config schema definition. I am not sure if that should be bundled with this fix. Something like this resolves both issues:
Comment #8
rohan-sinha commentedReviewed Patch #3 , issue has been resolved.
Comment #9
jeroentComment #11
jeroentCommitted and pushed to 8.x-1.x. Thanks!
Comment #12
jeroentOpened a follow-up issue for the config schema: #3343987: Missing config schema for search_api_location require option