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).
conditional_field_config
- 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).
error_on_save

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'])

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

gidel created an issue. See original summary.

gidel’s picture

Here a patch to apply on projects if nedded.

gidel’s picture

StatusFileSize
new981 bytes