Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\views\Plugin\views\display\DisplayPluginBase

Created on 9 November 2022, about 2 years ago
Updated 31 August 2023, over 1 year ago

Problem/Motivation

I am receiving following warning :

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\views\Plugin\views\display\DisplayPluginBase->viewExposedFormBlocks() (line 2626 of /core/modules/views/src/Plugin/views/display/DisplayPluginBase.php)

I have seen this warning very often after I upgraded PHP to 8.1.x but one way how to replicate the issue is :

1.Create new node
2.Edit that node like node/10/edit
3.Delete that node like node/10/delete
4.Visit that page : node/10/edit
5.You will be forwarded to 404 (Nothing found) and then click to homepage or to any other page and above warning will be displayed.

I know it does not make sense to visit currently deleted node, but this is the way how to replicate the issue very fast. As I already mentioned - i have seen other cases when the same warning occurred.

πŸ› Bug report
Status

Closed: cannot reproduce

Version

9.5

Component
PluginΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡ΈπŸ‡°Slovakia coaston

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Since there hasn't been a follow up to #9 going to close for now.

    If still a bug please reopen adding steps to reproduce to the issue summary.

    Thanks.

  • πŸ‡¨πŸ‡¦Canada gordonio

    I have been able to reproduce this issue with the following:

    1. Add a view to a global section of the site (Mine is an exposed form search block in the site header)
    2. Go to a url that gives you a 404.

    In the following, $route_name returns null and then fails the strpos.

    
      public function viewExposedFormBlocks() {
        // Avoid interfering with the admin forms.
        $route_name = \Drupal::routeMatch()->getRouteName();
        if (strpos($route_name, 'views_ui.') === 0) {
          return;
        }
        $this->view->initHandlers();
    
        if ($this->usesExposed() && $this->getOption('exposed_block')) {
          /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
          $exposed_form = $this->getPlugin('exposed_form');
          return $exposed_form->renderExposedForm(TRUE);
        }
      }
    
  • I am getting the same warning when images on the page have broken links and the exposed form search block in the site header is enabled. There are no warning upon disabling that block. I have to rebuild the cache each time.

Production build 0.71.5 2024