0

Am able to get the configured conditional fields in hook_field_widget_WIDGET_TYPE_form_alter() and trying to apply them for Paragraph fields but not working, below is the code(most of it copied from Conditional Fields module file):

$dependencies = conditional_fields_load_dependencies('paragraph', 'paragraph_machine_name');

    if (!empty($dependencies)) {
      foreach ($element['subform'] as $field_name => $field_details) {
        if (isset($dependencies['dependents'][$field_name])) {
          foreach ($dependencies['dependents'][$field_name] as $id => $dependency) {
            if (!isset($element['subform']['#conditional_fields'][$field_name]['dependees'][$id])) {
              conditional_fields_attach_dependency($element['subform'], ['#field_name' => $dependency['dependee']], $field_details, $dependency['options'], $id);
            }
          }
        }

        if (isset($dependencies['dependees'][$field_name])) {
          foreach ($dependencies['dependees'][$field_name] as $id => $dependency) {
            if (!isset($element['subform']['#conditional_fields'][$field_name]['dependents'][$id])) {
              conditional_fields_attach_dependency($element['subform'], $field_details, ['#field_name' => $dependency['dependent']], $dependency['options'], $id);
            }
          }
    }

  }
}

Can someone please help me in it?

  • which drupal version ? – berramou May 22 at 11:28
  • Drupal 8.7 version – Ajay May 24 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.