Adding a condition 'empty' on media field causes fatal error when trying to save a block

Created on 26 March 2025, about 1 month ago

Problem/Motivation

If I add a condition on a field, controlled by a media field with the "empty" condition, the block creation failed with a fatal error.
"Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateDependency()"

Steps to reproduce

- Use conditional_fields (4.0.0-alpha6), media and media_library.
- Create a block content with a media field, and another field (which will be the target field)
- Add a condition for the block (admin/structure/conditional_fields/block_content): set a target field, and the media field as "controlled by". Set the condition to "Empty" (for example: if media field is empty, hide the target field).

- Add a content block (/block/add), and fill the fields (the media field can be fiiled or let empty).
- Click on "save" button.
- A fatal error occurs with the message : Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateDependency() (line 936 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).

Proposed resolution

Add a condition (like already added for the !empty condition in the evaluateDependency() method) to check if the variable $values is an array before trying to assign an array key of the variable ($values[0]['value'])

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇫🇷France gidel

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