addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection::escapeLike()

Created on 6 May 2022, about 2 years ago
Updated 27 October 2023, 8 months ago

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

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States pianomansam

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024