I have a field collection (B) that is set within another field collection (A). I am trying to toggle the visibility of B using another field that is also in A. I have set up an appropriate dependency but toggling the field has no discernable impact on the field collection.

I have disabled all other modules to check for compatibility issues but this does not improve the situation. I am able to get the desired functionality within a field collection if both the dependent and dependee are fields. But not when the dependent is a field collection and the dependee is a field. I am also able to get the desired functionality if i move field collection B and the dependee field outside of their parent field collection and into the top level of the content type. It is only when i try to do this within another field collection that i am experiencing the above behavior.

I am not super familiar with conditional fields but if someone could point me in the right direction i would be more than willing to look into this.

#23 conditional_fields-fix_for_collections_12.patch1.04 KBkenorb
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View
#19 conditional_fields-fix_for_collections_19.patch1.07 KBocastle
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View


k.dani’s picture

Same problem...

liquidcms’s picture

i have same issue.

project i am on will fund getting this to work if anyone wants to tackle it; or will look at it myself when i get a chance.

pirog’s picture


we have some extra bandwidth and would be more than willing to tackle the issue if you could get some fundtion for it!

liquidcms’s picture

@pirog contact me at peter@liquidcms.ca

liquidcms’s picture

starting to dig into this a little and right off the bat i see issue appears to be that in conditional_fields_form_after_build() the dependency info is looked at for each field that has been assigned as dependent; and for my field there is no dependee info set; so function exits - and no JS is loaded.

liquidcms’s picture

it is this code that fails for the dependee field (field collection trying to be made invisible based on simple list field):

  // Some fields do not have entity type and bundle properties. In this case we
  // try to use the properties from the form. This is not an optimal solution,
  // since in case of fields in entities within entities they might not correspond,
  // and their dependencies will not be loaded.
  if (isset($field['#entity_type'], $field['#bundle'])) {
    $entity_type = $field['#entity_type'];
    $bundle = $field['#bundle'];
  elseif (isset($form['#entity_type'], $form['#bundle'])) {
    $entity_type = $form['#entity_type'];
    $bundle = $form['#bundle'];
  else {
    return $element;

which returns the wrong values to pass for this:

$dependencies = conditional_fields_load_dependencies($entity_type, $bundle);
liquidcms’s picture

and sure enough, if i statically force in the right values; everything works fine.. :) so just need to figure out the additional cases required for that clause to pull the correct $entity_type and $bundle values.

liquidcms’s picture

Status: Active » Needs review
1.3 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch conditional_fields-fix_for_collections.patch. Unable to apply patch. See the log in the details link for more information. View

i am sure this isn't the proper patch as i likely took a few liberties with my specific application; but should be a decent starting point.

liquidcms’s picture

my guess is my new test case is different than the one that i designed the patch above for; as it doesn't work in this case.

i switched around the 2 elseif clauses and it now works for my current case; but not sure it would still work for the case i originally had; my guess is it does.

semiaddict’s picture

The patch in #8 works great for me.
Thank you.

semiaddict’s picture

925 bytes
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in conditional_fields-fix_for_collections_11.patch. View

I ended up having to make a slight change in #8's patch to make it work with my setting, but I think this new patch should work for most if not all settings.

MO’s picture

Patch in #11 worked - Jumping for joy; albeit more baldly now!


Please help roll this dual patch to a release: https://drupal.org/node/2088101

MO’s picture

Issue summary: View changes

a little extra precision

Jody Lynn’s picture

Patch in 11 works for me.

There is still a slight problem in that if you have required fields that are triggered by conditionals, and you add another field collection, you can end up with two 'required' asterisks on your fields.

kenorb’s picture

ocastle’s picture

Patch #11 also works for me. Thanks!

kenorb’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 8: conditional_fields-fix_for_collections.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: conditional_fields-fix_for_collections_11.patch, failed testing.

ocastle’s picture

1.07 KB
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View

Reformatted Patch to be correct format and diff'd against dev branch

ocastle’s picture

Status: Needs work » Reviewed & tested by the community
mdelpozo’s picture

patch #19 worked for me

Marfio’s picture

Working for me

As said #12 both patches resolves many problems for Field Collection anf Conditional Fields.

Thank you very much!!!

kenorb’s picture

1.04 KB
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View

Updating patch offsets against the latest dev.

jschrab’s picture

Given that the patch in #19 is marked as "Reviewed & tested by the community", what more is needed to get this patch into dev?

peterpoe’s picture

peterpoe’s picture

Status: Reviewed & tested by the community » Closed (duplicate)