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.
Comments
Comment #2
kris77 commentedComment #3
cweldon commentedI followed the steps described in the issue and confirmed it resolved it for me. I created a patch based on Kris77's suggested resolution
Comment #4
boromino commentedComment #5
tgaugesI adjusted the patch so it applies to
4.0.0-alpha1.Comment #6
ivnish#5 works
Comment #7
ivnishComment #8
colanThis looks fine, but (minor nit) can we combine these into a single line?
$entity_type_id = $form_state->getFormObject()->getEntity()->getEntityTypeId();Shrinking the size of the method is more important than having less than 80 characters per line IMHO, and this would only be slightly over.
Comment #9
rassoni commentedAddressed #8feedback. Please review.
Comment #10
rishi.kulshreshtha#9 looks good, and got applied cleanly to 4.x-dev as well. Marking this as RTBC.
Comment #12
heddnThanks for your contributions.