Problem/Motivation

On PHP 8.1, when attempting to create a new node that has a message subscribe flag, I receive the following deprecation notice:

Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1483 of core/lib/Drupal/Core/Database/Connection.php).
Drupal\Core\Database\Connection->escapeLike(NULL) (Line: 418)
Drupal\Core\Database\Query\Select->escapeLike(NULL) (Line: 118)
Drupal\Core\Entity\Query\Sql\Condition::translateCondition(Array, Object, ) (Line: 63)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 176)
Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 80)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 233)
Drupal\flag\FlagService->getAllEntityFlaggings(Object, Object, '4BkypIt50CpddZxjE-QGzY9r1ilH6Zh0AzMqDhlG5d9twH-x') (Line: 24)
message_subscribe_email_flag_action_access('flag', Object, Object, Object)

Steps to reproduce

Run a Drupal 9 site on PHP 8.1, attach a subscribe flag to a node, and go to create one of those nodes.

Proposed resolution

Upon further inspection of `message_subscribe_email_flag_action_access()`, it appears that while it checks for `$flaggable` to be truthy, this is not sufficient as `$flaggable` can be truthy before the node has been created. We should probably add a check that `$flaggable` is an entity that exists. A simple check for `$flaggable->id()` being truthy should suffice.

Remaining tasks

Create patch or PR.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
#4 php-81-deprecation-notices.patch969 bytesedmund.dunn
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

pianomansam created an issue. See original summary.

pianomansam’s picture

Status: Active » Needs review

I have created a issue fork and PR to perform my suggestion solution, and it appears to have cleared up the deprecation notices.

edmund.dunn’s picture

StatusFileSize
new969 bytes

Here is a patch file for the above PR.

Status: Needs review » Needs work

The last submitted patch, 4: php-81-deprecation-notices.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pianomansam’s picture

Status: Needs work » Needs review

Bad bot! This PR is ready for review. If tests aren't passing, it's not because of the 1 line this PR changes.

avpaderno’s picture

Title: PHP 8.1 Deprecated function notices » addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection::escapeLike()
Version: 8.x-1.1 » 8.x-1.x-dev
Issue tags: +PHP 8.1
ultrabob’s picture

Status: Needs review » Reviewed & tested by the community

I'm not deeply familiar with this module, but the code change makes sense to me, applies cleanly, and fixes the issue reported.

bluegeek9’s picture

+1 Reviewed & tested by the community

alfthecat’s picture

Patch applied and resolved the issue.

In my case message subscribe was merely installed and not setup or attached to anything. Strangely, when trying to open the media library to add an image to a node, the site crashed with this error.

  • bluegeek9 committed 02940119 on 8.x-1.x authored by pianomansam
    Issue #3279287 by edmund.dunn:  addcslashes(): Passing null to parameter...
bluegeek9’s picture

Status: Reviewed & tested by the community » Fixed
alfthecat’s picture

Happy this is committed! Thanks @bluegeek9

Status: Fixed » Closed (fixed)

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