
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'])
Comment | File | Size | Author |
---|---|---|---|
#4 | issue-3515565_3.patch | 981 bytes | gidel |
conditional_field_config.png | 14.13 KB | gidel | |
error_on_block_save.png | 94.48 KB | gidel |
Issue fork conditional_fields-3515565
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
Comment #2
gidel CreditAttribution: gidel at Smile commentedHere a patch to apply on projects if nedded.
Comment #4
gidel CreditAttribution: gidel at Smile commented