conditional_fields.module | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/conditional_fields.module b/conditional_fields.module index 5b50edd..a8885a2 100644 --- a/conditional_fields.module +++ b/conditional_fields.module @@ -1082,6 +1082,46 @@ function conditional_fields_evaluate_dependency($context, $values, $options) { $values = array(array('value' => $values)); } + // In the context of edit we have to handle value differently. + // TODO: Does the view really work as it should? showing the right fields at the right conditions? + if ($options['condition'] === 'value' && $context == 'edit') { + // $dependency_values might be a single string-value + // will convert to an array, it's easier that way + if (!is_array($dependency_values)) { + $dependency_values = array($dependency_values => $dependency_values); + } else { + // If we have a [*]['value'] structure well unpack it, so we work better with it. + if (isset($dependency_values[0]['value'])) { + $tmp_values = array(); + foreach ($values as $value) { + $val = $value['value']; + $tmp_values[$val] = $val; + } + $values = $tmp_values; + } + // Filter out the NULL-Values, as we don't care about those + $dependency_values = array_diff($dependency_values, array_filter($dependency_values, 'is_null')); + } + + + if (!is_array($values)) { + $values = array($values => $values); + } else { + // If we have a [*]['value'] structure well unpack it, so we work better with it. + if (isset($values[0]['value'])) { + $tmp_values = array(); + foreach ($values as $value) { + $val = $value['value']; + $tmp_values[$val] = $val; + } + $values = $tmp_values; + } + + // Filter values we don't care about, so we can compare these arrays later + $values = array_intersect_key($dependency_values, array_filter($values, 'is_string')); + } + } + // If we are in form context, we are almost done. if ($context == 'edit') { // If $dependency_values is not an array, we can only assume that it