Module is worthless on PHP8.1 as it has two deprecated functions.

Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Xss::filter() (line 69 of /home/sitename/public_html/core/lib/Drupal/Component/Utility/Xss.php).

Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Unicode::validateUtf8() (line 478 of /home/sitename/public_html/core/lib/Drupal/Component/Utility/Unicode.php).

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

Christopher Riley created an issue. See original summary.

cilefen’s picture

Hi: those are deprecation warnings, not errors. These warnings must be addressed but do not affect code operation.

Christopher Riley’s picture

I beg to differ as it seems to be preventing me from being able to adjust a table field that I have within a paragraph. As soon as I disable the module the issue goes away.

Suggestions?

Christopher Riley’s picture

I did a big of digging and I think that this is because I have a unique setup. As I mentioned this is within a Paragraph and Within a Field Group.

When I have the modules enabled and it is running into a NULL return from the call

$setting = $plugin->getThirdPartySetting('field_delimiter', 'delimiter');

within the field_delimiter_field_formatter_third_party_settings_form function.

I think a simple test to validate the field that is being called is a legit form field would be sufficient.

What do you think?

Christopher Riley’s picture

I went ahead and rolled a patch for this issue in case you decide to use it.

joelseguin’s picture

Thanks @Christopher Riley for the patch. I've applied to one of my sites and it definitely addresses the deprecation warnings (which was quite a lot of unnecessary scrolling when doing site building tasks).

avpaderno’s picture

Title: PHP 8.1 Deprecated Function » str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Xss::filter()
Status: Active » Needs review
Issue tags: +PHP 8.1
avpaderno’s picture

Status: Needs review » Needs work
-    $safe_delimiter = Xss::filter($setting, array('br', 'hr', 'span', 'img', 'wbr'));
+    $safe_delimiter = !is_null($setting) ? Xss::filter($setting, array('br', 'hr', 'span', 'img', 'wbr')) : '';

It should use short array syntax, as the currently used code. (That is also what the Drupal coding standards suggest to use, if I correctly recall.)
I would also use isset($setting) ? Xss::filter($setting, ['br', 'hr', 'span', 'img', 'wbr']) : '' which avoids to use a negation.

pflora’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB

Here's a patch with the requested changes from #8! Moving this to NR.

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

The last patch changes the code as suggested.

dunebl’s picture

+1 RTBC

a.sotirov’s picture

+1 RTBC
It works on my site with Drupal Core 9.5.3 and php 8.1.

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

urvashi_vora’s picture

Reviewed and tested the patch #9, works well for me as well.

LGTM, RTBC++

Committing the changes for helping the maintainer.

yevko’s picture

+ LGTM

claudiu.cristea’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

There's already a 2.0.x branch

avpaderno’s picture

Issue tags: +Needs reroll
solideogloria’s picture

Issue tags: -Needs reroll

Patch #9 applies correctly to 2.x-dev. No reroll is required.

j_s’s picture

Patch #9 worked well! Thanks!

phannphong’s picture

I can confirm that the patch #9 works like a charm. Thank you!

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs merge request

The merge request is not for the 2.x branch. That is why the Needs reroll tag was added.

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

  • pcambra committed 8d935ca3 on 2.0.x authored by urvashi_vora
    Issue #3301169: str_replace(): Passing null to parameter #3 ($subject)...
pcambra’s picture

Status: Needs work » Fixed

Merged into 2.x, thanks all!

Status: Fixed » Closed (fixed)

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