Problem/Motivation

For some reason the 'breadcrumb' key is sometimes not in $vars in the preprocess breadcrumb hook.

The error shows up as a warning on the site.

Warning
: foreach() argument must be of type array|object, null given in
/var/www/html/docroot/modules/contrib/html_title/html_title.module
on line
88

Steps to reproduce

I'm trying to use Breadcrumbs with facetted search connected to solr and the error shows up when there's no search parameters.

  • Drupal 10.2.5
  • PHP 8.3
  • Search API 1.34

Proposed resolution

Add a simple check for the 'breadcrumb' keys in the $vars array in the preprocess_breadcrumb hook.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork html_title-3444698

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:

Comments

dmlb2000 created an issue. See original summary.

dmlb2000’s picture

Issue summary: View changes

quadrexdev made their first commit to this issue’s fork.

quadrexdev’s picture

Assigned: dmlb2000 » Unassigned
Status: Active » Needs review

"isset" check should be enough even though

$variables['breadcrumb']

is supposed to be an empty array by default. Please see

template_preprocess_breadcrumb()
vitaliyb98’s picture

This issue could not be reproduced on a "fresh install" without other modules. However, one possible cause is the order in which hook_preprocess_breadcrumb functions are executed. In this module, html_title_preprocess_breadcrumb is hardcoded to run after all other preprocess functions.

As a result, this problem can occur if a contributed module or custom code does something like the following:

function boo_preprocess_breadcrumb(&$vars) {
  $vars['breadcrumb'] = NULL;
}

In my opinion, committing this fix will improve the stability of the module.

vitaliyb98’s picture

Status: Needs review » Fixed

Merged into 8.x-1.x, thanks

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.