Problem/Motivation

on loading a view with pictures following error is thrown:

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in template_preprocess_colorbox_formatter() (line 88 of modules/contrib/colorbox/colorbox.theme.inc).

Using Drupal core 9.3.9 with php 8.1.4

Issue fork colorbox-3272796

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

bart lambert created an issue. See original summary.

victoria-marina’s picture

Assigned: Unassigned » victoria-marina

Working on this

victoria-marina’s picture

Assigned: victoria-marina » Unassigned
Status: Active » Needs review

Hope it helps!

avpaderno’s picture

Title: Deprecated functions » Passing null to parameter #1 ($haystack) of type string to strpos() is deprecated
Version: 8.x-1.8 » 8.x-1.x-dev
Issue tags: -Deprecated function +deprecated
muranod’s picture

Setting up a new site, I'm getting this, and other similar error messages as well, though Colorbox is working beautifully.

in addition the the above:

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in template_preprocess_colorbox_formatter() (line 88 of ... \web\modules\contrib\colorbox\colorbox.theme.inc)

Drupal 9, all modules up to date. Using Bootstrap 5 theme.
Colorbox Version: 8.x-1.8

bart lambert’s picture

Corrected line 86 of the colorbox.theme.inc .

I have no errors yet, everything working fine! Thanks!

ruturaj chaubey’s picture

Status: Needs review » Reviewed & tested by the community

No errors. Working fine.

renatog’s picture

Really makes sense. +1 to RTBC

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Merged to the dev branch

Thank you so much @victoria-marina and everyone for your contribution

muranod’s picture

I love Colorbox. Thank you for the quick fix!

parijke’s picture

Sorry for asking, but how do I make a patch file out of this?

apolitsin’s picture

Status: Fixed » Needs work

Still have this problem

Error message
Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in template_preprocess_colorbox_formatter() (line 115 of modules/contrib/colorbox/colorbox.theme.inc).
template_preprocess_colorbox_formatter(Array, 'colorbox_formatter', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('colorbox_formatter', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)

how to fix

```diff
// Do not output an empty 'title' attribute.
- if (strlen($item->title) != 0) {
+ if (strlen((string) $item->title) != 0) {
```
avpaderno’s picture

That is a different error message, although similar to the one reported in the issue summary.

We can either leave this issue closed and create a new issue, or re-open this and update the issue summary; in the latter case, it would be better to fix all similar errors.
Usually, once the issue is marked fixed, it's not re-opened, but that is a decision the project maintainers make.

avpaderno’s picture

If we are going to fix also the following code, I would not convert $item->title to a string.

// Do not output an empty 'title' attribute.
if (strlen($item->title) != 0) {
  $variables['image']['#title'] = $item->title;
  $data_cbox_img_attrs['title'] = '"title":"' . $item->title . '"';
}

It's sufficient to use the following code.

// Do not output an empty 'title' attribute.
if (!empty($item->title)) {
  $variables['image']['#title'] = $item->title;
  $data_cbox_img_attrs['title'] = '"title":"' . $item->title . '"';
}
avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new532 bytes
apolitsin’s picture

Status: Needs review » Reviewed & tested by the community

The patch works perfectly, thanks

avpaderno’s picture

The tests fail, but it's because I selected MySQL 5.6 and Drupal 9.3, when Drupal 9.3 requires MySQL 5.7.

The database server version 5.6.40 is less than the minimum required version 5.7.8.

renatog’s picture

Really looks good. Thanks a lot

  • RenatoG committed fd51a8c on 8.x-1.x authored by apaderno
    Issue #3272796 by RenatoG, victoria-marina, apaderno, bart lambert,...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Committed to the 8.x-1.x branch. Thank you so much everyone for your job on this

muranod’s picture

Worked for me!
Thanks for the quick fix.

Status: Fixed » Closed (fixed)

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