Undefined index: #entity_type in Drupal\conditional_fields\ConditionalFieldsFormHelper::dependentValidate() (line 331

Created on 13 January 2020, about 5 years ago
Updated 27 September 2023, over 1 year ago

In my content type there are two fields: field_1(boolean) and field_2(file attachment).

Manage Dependies: field_2 is visible when field_1 has value "ON"

When try to create content and click on save, show this error:
"Undefined index: #entity_type in Drupal\conditional_fields\ConditionalFieldsFormHelper::dependentValidate() (line 331...modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php)"

So, I have insert this in ConditionalFieldsFormHelper.php file on line 331:

 $entity_type = '';

            if (!empty($form['#entity_type'])) {
               $entity_type = $form['#entity_type'];
            }

Then replace this

$field = FieldStorageConfig::loadByName($form['#entity_type'], $dependent['field_parents'][0]);

With this:

$field = FieldStorageConfig::loadByName($entity_type, $dependent['field_parents'][0]);

and error is gone.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇮🇹Italy kris77

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024