diff --git a/conditional_fields.module b/conditional_fields.module index 34503a6..15df3c0 100644 --- a/conditional_fields.module +++ b/conditional_fields.module @@ -585,47 +585,45 @@ function conditional_fields_form_after_build($form, &$form_state) { unset($behaviors); - if (empty($states)) { - continue; - } - // Save the modified field back into the form. drupal_array_set_nested_value($form, $dependent_location, $dependent_form_field); - // Map the states based on the conjunctions. - $states_new = array(); - foreach ($states as $state_key => $value) { - // As the main object is ANDed together we can add the AND items directly. - if (!empty($states[$state_key]['AND'])) { - $states_new[$state_key] = $states[$state_key]['AND']; - } - // The OR and XOR groups are moved into a sub-array that has numeric keys - // so that we get a JSON array and not an object, as required by the States - // API for OR and XOR groupings. - if (!empty($states[$state_key]['OR'])) { - $or = array(); - foreach ($states[$state_key]['OR'] as $constraint_key => $constraint_value) { - $or[] = array($constraint_key => $constraint_value); + if (!empty($states)) { + // Map the states based on the conjunctions. + $states_new = array(); + foreach ($states as $state_key => $value) { + // As the main object is ANDed together we can add the AND items directly. + if (!empty($states[$state_key]['AND'])) { + $states_new[$state_key] = $states[$state_key]['AND']; } - // '1' as a string so that we get an object (which means logic groups - // are ANDed together). - $states_new[$state_key]['1'] = $or; - } - if (!empty($states[$state_key]['XOR'])) { - $xor = array('xor'); - foreach ($states[$state_key]['XOR'] as $constraint_key => $constraint_value) { - $xor[] = array($constraint_key => $constraint_value); + // The OR and XOR groups are moved into a sub-array that has numeric keys + // so that we get a JSON array and not an object, as required by the States + // API for OR and XOR groupings. + if (!empty($states[$state_key]['OR'])) { + $or = array(); + foreach ($states[$state_key]['OR'] as $constraint_key => $constraint_value) { + $or[] = array($constraint_key => $constraint_value); + } + // '1' as a string so that we get an object (which means logic groups + // are ANDed together). + $states_new[$state_key]['1'] = $or; + } + if (!empty($states[$state_key]['XOR'])) { + $xor = array('xor'); + foreach ($states[$state_key]['XOR'] as $constraint_key => $constraint_value) { + $xor[] = array($constraint_key => $constraint_value); + } + // '2' as a string so that we get an object. + $states_new[$state_key]['2'] = $xor; } - // '2' as a string so that we get an object. - $states_new[$state_key]['2'] = $xor; } - } - $states = $states_new; + $states = $states_new; - // Add the #states property to the dependent field. - drupal_array_set_nested_value($form, array_merge($dependent_location, array('#states')), $states); + // Add the #states property to the dependent field. + drupal_array_set_nested_value($form, array_merge($dependent_location, array('#states')), $states); - $has_states = TRUE; + $has_states = TRUE; + } } if (empty($has_states)) {