Problem/Motivation

Using Flag on PHP 8.1 produces the following PHP deprecation message:

Deprecated function: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in Drupal\Core\Access\RouteProcessorCsrf->processOutbound()

Proposed resolution

Fix the deprecation message.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review
StatusFileSize
new692 bytes

Attached patch fixes the PHP deprecation message when running Flag on PHP 8.1

zengenuity’s picture

The patch in #2 works for me.

tr’s picture

Status: Needs review » Reviewed & tested by the community

I triggered DrupalCI testing with PHP 8.1 and this patch eliminates the PHP deprecation errors for str_replace().

tr’s picture

Issue tags: +PHP 8.1
gagarine’s picture

I confirm patch #2 works for me. Tested on live website.

neclimdul’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/ActionLink/ActionLinkTypeBase.php
@@ -100,7 +100,10 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
-      $url->setRouteParameter('destination', $this->getDestination());

This should suppress the notice but the getDestination should always return a string. The problem is that AJAXactionLink doesn't return the destination when it should.

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new451 bytes

This should be the correct fix.

tr’s picture

Status: Needs review » Reviewed & tested by the community

Much better. This is why all the issues reported by static analysis should be fixed - they're just problems waiting to happen:

 ------ ----------------------------------------------------------------------- 
  Line   src/Plugin/ActionLink/AJAXactionLink.php                               
 ------ ----------------------------------------------------------------------- 
  73     Method Drupal\flag\Plugin\ActionLink\AJAXactionLink::getDestination()  
         should return string but return statement is missing.                  
 ------ ----------------------------------------------------------------------- 

There are at least four other places that also have missing returns.

Note the PHP 8.1 / pgsql-10.12 fails are *branch* failures and have nothing to do with the patch. They need to be addressed in a separate issue.

neclimdul’s picture

100% agree about static analysis! Glad we can fix two problems with one patch. :-D

trebormc’s picture

I confirm patch #8 works for me. Tested on PROD website.

pebosi’s picture

Patch is working for me, too. A new module release would be great.

klemendev’s picture

RTBC, our logs are filling up by this error and this fixed the issue

agathacrystal’s picture

#8 is also working for me! Thanks for the patch!

  • Berdir committed 6bde5aa on 8.x-4.x authored by neclimdul
    Issue #3266574 by idebr, neclimdul: [PHP8.1] Deprecated function:...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

agathacrystal’s picture

I'm still a little new to the patching process. So forgive me, if im missing something.

After updating my composer.json, the patch cant be applied anymore.
I guess this is because it got 'fixed' - BUT the initial error occurs again.

berdir’s picture

The patch is only in the development snapshot, it should still apply if you use the most recent release.

If not, you could try #support or so in slack for support, projects issues (especialy closed ones) aren't really a good place for that.

agathacrystal’s picture

Ok, thanks for the info & sorry!

Status: Fixed » Closed (fixed)

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

rajab natshah’s picture

Thanks, using the committed fix
6bde5aa.patch

Hoping for a release tag.

bserem’s picture

Now that PHP 7.4 is EOL, can we get a new release for flag?

Thanks

nathan tsai’s picture

Just updating this thread: release 8.4.0-beta4 has this patch applied.

composer require 'drupal/flag:^4.0@beta'
robin_rosh’s picture

I'm still facing the same issue even after upgrading from 9.5 to 10.5, specifically with flag 5.0

ivnish’s picture

How to reproduce this?