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

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

Proposed resolution

It should be able to handle the fact that a field might not have 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

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

Rob230 created an issue. See original summary.

rob230’s picture

Issue summary: View changes
rob230’s picture

StatusFileSize
new663 bytes

Patch to add null coalescing operator. Casting to string would also work.

rob230’s picture

Issue summary: View changes

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

abhishek_gupta1’s picture

Status: Active » Needs review

@colan, fixed the issue and created. please kindly review the MR

liam morland’s picture

If $reference_value is empty, then it won't match the regex anyway so might as well avoid the call.

dqd’s picture

Status: Needs review » Needs work

regarding #8

dineshkumarbollu’s picture

Status: Needs work » Needs review
StatusFileSize
new686 bytes

Based on #8 made changes.

dqd’s picture

Regarding ?? vs ?: vs !=NULL see following code test examples: https://3v4l.org/McavC

dqd’s picture

Version: 4.0.0-alpha5 » 4.x-dev
heddn’s picture

Status: Needs review » Needs work

See most recent comments.

prem suthar made their first commit to this issue’s fork.

prem suthar’s picture

Status: Needs work » Needs review

Try To Addressed the #8 point .

liam morland’s picture

The best thing might just to be cast to string; see merge request. The problem with empt() is that 0 is empty.

heddn’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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