PHP notice with Drupal 9.5 - Search API location views

Created on 20 February 2023, over 1 year ago
Updated 23 February 2023, over 1 year ago

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
      }
    }
  }
🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom aaron.ferris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024