PHP 8.1 issue with preg_match()

Created on 2 January 2024, 12 months ago

Problem/Motivation

If you have a value condition using a regular expression condition, but the field has no value (including for example on the new content form) then it causes an error:

Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateDependency() (line 793 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).

Steps to reproduce

Create an entity reference field which uses a select widget. The field should not be required.
Create another field (e.g. a text field).
Add a conditional field to control visibility of this 2nd field based on the 1st (entity reference) field.
Choose "Condition" = "Value".
Choose "Values input mode" = "Regular expression..."
Enter a regular expression which will match one of the values in the entity reference field.
Edit some content which doesn't have a value for the entity reference field.
Save the content.
The deprecation appears.

Proposed resolution

It should be able to handle the fact that a field might not a value.

Now that PHP 8.1 requires string values to string functions, the simplest thing would be to cast the value and this will maintain the PHP 7 behaviour.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Rob230

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024