diff --git a/conditional_fields.module b/conditional_fields.module
index 5b50edd..23e0e44 100644
--- a/conditional_fields.module
+++ b/conditional_fields.module
@@ -202,6 +202,7 @@ function conditional_fields_forms() {
/**
* Implements hook_element_info_alter().
+ *
* Adds an #after_build function to all form elements.
*/
function conditional_fields_element_info_alter(&$types) {
@@ -211,6 +212,68 @@ function conditional_fields_element_info_alter(&$types) {
}
/**
+ * Implements hook_field_group_build_pre_render_alter().
+ *
+ * Have to wait for the group elements to be created - unfortunately
+ * this is after after_build.
+ */
+function conditional_fields_field_group_build_pre_render_alter(&$element) {
+ // Have to re-process conditional fields over again for newly created
+ // fieldgroup elements (and existing elements moved to fieldgroup children)
+ // If this isn't for a form (i.e., being called because the entity is
+ // being viewed), just return.
+ if (!isset($element['#form_state']) || empty($element['#form_state'])) {
+ return;
+ }
+ // $form_state is added to $form['#form_state'] via
+ // conditional_fields_form_after_build().
+ $form_state = $element['#form_state'];
+ $form_state['complete form'] = $element;
+ $form = &$form_state['complete form'];
+ // Loop through fieldgroups and fieldgroup children.
+ $new_dependents = array();
+ foreach ($form['#fieldgroups'] as $group_name => $group) {
+ // Call element_after_build for fieldgroup children.
+ foreach ($group->children as $field_name) {
+ $parents = array_merge($group->array_parents, array($field_name));
+ $field_element = &drupal_array_get_nested_value($form, $parents);
+ conditional_fields_element_after_build($field_element, $form_state, TRUE);
+ }
+ // Call element_after_build for fieldgroup element.
+ $group_element = &drupal_array_get_nested_value($form, $group->array_parents);
+ $group_element['#field_name'] = $group_name;
+ // Make sure group element has an ID to select in drupal_process_states.
+ $group_element['#id'] = isset($group_element['#id']) ? $group_element['#id'] : $group_name;
+ // Need to wrap markup type with a div with the ID, unless ID
+ // already present in prefix or markup.
+ if (isset($group_element['#type']) && $group_element['#type'] == 'markup') {
+ if ((!isset($group_element['#prefix']) || !strstr($group_element['#prefix'], '#' . $group_element['#id']))
+ && (!isset($group_element['#markup']) || !strstr($group_element['#markup'], '#' . $group_element['#id']))
+ ) {
+ $group_element['#prefix'] = '
' . (isset($group_element['#prefix']) ? $group_element['#prefix'] : '');
+ $group_element['#suffix'] = (isset($group_element['#suffix']) ? $group_element['#suffix'] : '') . '
';
+ }
+ }
+ conditional_fields_element_after_build($group_element, $form_state, TRUE);
+ if (isset($form['#conditional_fields'][$group_name], $form['#conditional_fields'][$group_name]['dependees'])) {
+ $new_dependents[$group_name] = &$group_element;
+ }
+ }
+
+ // Call form_after_build.
+ $form = conditional_fields_form_after_build($form, $form_state, TRUE);
+
+ // Call validation for group dependents.
+ foreach ($new_dependents as $dependent_name => &$dependent) {
+ conditional_fields_dependent_validate($dependent, $form_state, $form);
+ }
+ // Call form validation.
+ conditional_fields_form_validate($form, $form_state);
+
+ $element = $form;
+}
+
+/**
* Processes form elements with dependencies.
*
* Just adds a #conditional_fields property to the form with the needed
@@ -218,7 +281,7 @@ function conditional_fields_element_info_alter(&$types) {
* - The fields #parents property.
* - Field dependencies data.
*/
-function conditional_fields_element_after_build($element, &$form_state) {
+function conditional_fields_element_after_build($element, &$form_state, $reprocess = FALSE) {
// Some fields are wrapped in containers before processing. Wrapped data must
// take precedence over the container, because Entity Translation and
// possibly other modules add #field_name to the container as well.
@@ -239,10 +302,14 @@ function conditional_fields_element_after_build($element, &$form_state) {
return $element;
}
+ // Get fieldgroup name if field belongs to one.
+ $group_name = isset($form['#group_children']) && isset($form['#group_children'][$field['#field_name']]) ?
+ $form['#group_children'][$field['#field_name']] : NULL;
+
// 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.
+ // 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'];
@@ -264,19 +331,32 @@ function conditional_fields_element_after_build($element, &$form_state) {
// Attach dependent.
if (isset($dependencies['dependents'][$field['#field_name']])) {
foreach ($dependencies['dependents'][$field['#field_name']] as $id => $dependency) {
- if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
+ if ($reprocess || !isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
}
}
}
+ // Also attach dependent if element is a (first) child in a dependent
+ // fieldgroup and the dependency state isn't 'visible' or 'hidden'
+ // (this is done on the fieldgroup element itself)
+ if ($group_name && isset($dependencies['dependents'][$group_name])) {
+ $group_dependent = $dependencies['dependents'][$group_name];
+ if (!in_array($group_dependent[key($group_dependent)]['options']['state'], array('visible', 'hidden'))) {
+ foreach ($group_dependent as $id => $dependency) {
+ if ($reprocess || !isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
+ conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
+ }
+ }
+ }
+ }
// Attach dependee.
// TODO: collect information about every element of the dependee widget, not
// just the first encountered. This bottom-up approach would allow us to
// define per-element sets of dependency values.
if (isset($dependencies['dependees'][$field['#field_name']])) {
foreach ($dependencies['dependees'][$field['#field_name']] as $id => $dependency) {
- if (!isset($form['#conditional_fields'][$field['#field_name']]['dependents'][$id])) {
+ if ($reprocess || !isset($form['#conditional_fields'][$field['#field_name']]['dependents'][$id])) {
conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependency['dependent']), $dependency['options'], $id);
}
}
@@ -402,6 +482,7 @@ function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $op
}
if (isset($dependent_parents)) {
$form['#conditional_fields'][$dependent['#field_name']]['field_parents'] = $dependent_parents;
+ $form['#conditional_fields'][$dependent['#field_name']]['array_parents'] = $dependent['#array_parents'];
$form['#conditional_fields'][$dependent['#field_name']]['dependees'][$id] = array(
'dependee' => $dependee['#field_name'],
'options' => $options,
@@ -426,6 +507,11 @@ function conditional_fields_form_after_build($form, &$form_state) {
return $form;
}
+ // Set $form_state in $form so hook_field_group_build_pre_render_alter
+ // has access to it when it is invoked after after_build.
+ // (when fieldgroup elements are attached to form)
+ $form['#form_state'] =& $form_state;
+
$effects = array();
$state_handlers = conditional_fields_states_handlers();
@@ -436,6 +522,12 @@ function conditional_fields_form_after_build($form, &$form_state) {
if (empty($dependent_info['dependees'])) {
continue;
}
+ if (isset($dependent_info['options']['group']) && $dependent_info['options']['group']) {
+ $is_group = TRUE;
+ }
+ else {
+ $is_group = FALSE;
+ }
$dependent_location = array_merge($dependent_info['field_parents'], array($dependent));
$dependent_form_field = drupal_array_get_nested_value($form, $dependent_location);
@@ -448,8 +540,15 @@ function conditional_fields_form_after_build($form, &$form_state) {
continue;
}
+ // Skip this dependency if it's a group element and state is not
+ // visible/hidden (dependencies for other states are attached to
+ // fieldgroup children elements)
+ if (in_array($dependent, array_keys($form['#fieldgroups'])) && !in_array($dependency['options']['state'], array('visible', 'hidden'))) {
+ continue;
+ }
$dependee_info = $form['#conditional_fields'][$dependee];
- $dependee_form_field = drupal_array_get_nested_value($form, $dependee_info['parents']);
+ $dependee_location = $dependee_info['parents'];
+ $dependee_form_field = drupal_array_get_nested_value($form, $dependee_location);
$options = $dependency['options'];
// Load field edit behaviors.
@@ -672,7 +771,12 @@ function conditional_fields_form_after_build($form, &$form_state) {
* @see conditional_fields_form_validate()
*/
function conditional_fields_dependent_validate($element, &$form_state, $form) {
- $dependent = $element[$element['#language']];
+ if (isset($element['#language'], $element[$element['#language']])) {
+ $dependent = $element[$element['#language']];
+ }
+ else {
+ $dependent = $element;
+ }
// Check if this field's dependencies were triggered.
if (conditional_fields_evaluate_dependencies($dependent, $form, $form_state)) {
@@ -693,7 +797,8 @@ function conditional_fields_dependent_validate($element, &$form_state, $form) {
// conditional_fields_form_validate().
$errors = form_get_errors();
- if ($errors) {
+ if ($errors && isset($dependent['#parents'])) {
+ // Group elements have no #parents key.
$error_key = implode('][', $dependent['#parents']);
foreach ($errors as $name => $error) {
// An error triggered by this field might have been set on a descendant
@@ -722,7 +827,10 @@ function conditional_fields_dependent_validate($element, &$form_state, $form) {
*/
function conditional_fields_field_get_values($element, $form_state) {
// Fall back to #parents to support custom dependencies.
- $parents = !empty($element['#field_parents']) ? $element['#field_parents'] : $element['#parents'];
+ // $parents = !empty($element['#field_parents']) ? $element['#field_parents'] : $element['#parents'];
+ // Should this be the other way around? Isn't #parents the parent keys
+ // in $form_state['values']?
+ $parents = isset($element['#parents']) ? $element['#parents'] : $element['#field_parents'];
return drupal_array_get_nested_value($form_state['values'], $parents);
}
@@ -765,8 +873,8 @@ function conditional_fields_form_validate($form, &$form_state) {
}
// Save the changed array back in place.
- // Do not use form_set_value() since it assumes that the values are located at
- // $form_state['values'][ ... $element['#parents'] ... ], while the
+ // Do not use form_set_value() since it assumes that the values are located
+ // at $form_state['values'][ ... $element['#parents'] ... ], while the
// documentation of hook_field_widget_form() states that field values are
// $form_state['values'][ ... $element['#field_parents'] ... ].
drupal_array_set_nested_value($form_state['values'], $dependent['#field_parents'], $field_values_location);
@@ -794,8 +902,8 @@ function conditional_fields_form_validate($form, &$form_state) {
$removed_messages[] = $error;
}
- // Reinstate remaining error messages (which, at this point, are messages that
- // were originated outside of the validation process).
+ // Reinstate remaining error messages (which, at this point, are messages
+ // that were originated outside of the validation process).
foreach (array_diff($error_messages['error'], $removed_messages) as $message) {
drupal_set_message($message, 'error');
}
@@ -846,11 +954,10 @@ function conditional_fields_entity_view_alter(&$build, $type) {
$evaluated_dependents = array();
foreach ($dependencies['dependents'] as $dependent => $dependency) {
- if (empty($build[$dependent]['#access'])) {
- continue;
- }
-
foreach ($dependency as $dependency_options) {
+ if (empty($build[$dependent]['#access']) && $dependency_options['type'] != 'group') {
+ continue 2;
+ }
$dependee = $dependency_options['dependee'];
$options = $dependency_options['options'];
@@ -923,7 +1030,12 @@ function conditional_fields_entity_view_alter(&$build, $type) {
case CONDITIONAL_FIELDS_FIELD_VIEW_EVALUATE:
// Hide the dependent if it is not triggered.
if (!$is_triggered) {
- $build[$dependent]['#access'] = FALSE;
+ if ($dependency_options['type'] == 'group') {
+ conditional_fields_hide_group($build, $dependent);
+ }
+ else {
+ $build[$dependent]['#access'] = FALSE;
+ }
}
break;
@@ -932,14 +1044,21 @@ function conditional_fields_entity_view_alter(&$build, $type) {
break;
case CONDITIONAL_FIELDS_FIELD_VIEW_HIDE_UNTRIGGERED_ORPHAN:
- // Hide the dependent if the dependee is not viewable and the dependency is not triggered.
+ // Hide the dependent if the dependee is not viewable
+ // and the dependency is not triggered.
if ($is_orphan && !$is_triggered) {
- $build[$dependent]['#access'] = FALSE;
+ if ($dependency_options['type'] == 'group') {
+ conditional_fields_hide_group($build, $dependent);
+ }
+ else {
+ $build[$dependent]['#access'] = FALSE;
+ }
}
break;
case CONDITIONAL_FIELDS_FIELD_VIEW_HIGHLIGHT:
- // Show the dependent themed like an error message if it is not triggered.
+ // Show the dependent themed like an error message
+ // if it is not triggered.
if (!$is_triggered) {
$build[$dependent]['#prefix'] = isset($build[$dependent]['#prefix']) ? '' . $build[$dependent]['#prefix'] : '
';
$build[$dependent]['#suffix'] = isset($build[$dependent]['#suffix']) ? $build[$dependent]['#suffix'] . '
' : '
';
@@ -947,7 +1066,8 @@ function conditional_fields_entity_view_alter(&$build, $type) {
break;
case CONDITIONAL_FIELDS_FIELD_VIEW_DESCRIBE:
- // Show a textual description of the dependency under the dependent field.
+ // Show a textual description of the dependency
+ // under the dependent field.
if ($build[$dependent]['#access']) {
$dependee_title = isset($build[$dependee]['#title']) ? $build[$dependee]['#title'] : $dependee;
$dependent_title = isset($build[$dependent]['#title']) ? $build[$dependent]['#title'] : $dependent;
@@ -976,6 +1096,60 @@ function conditional_fields_entity_view_alter(&$build, $type) {
}
/**
+ * Helper function to hide a group.
+ *
+ * @param array $build
+ * The build array.
+ * @param string $dependent
+ * The group name to be hidden.
+ */
+function conditional_fields_hide_group(&$build, $dependent) {
+ $all_children = _conditional_fields_get_all_progeny($build['#group_children'], $build['#groups'], $dependent);
+ foreach ($all_children as $child => $parent) {
+ if (in_array($child, $build['#groups'])) {
+ unset($build['#groups'][$child]);
+ }
+ else {
+ $build[$child]['#access'] = FALSE;
+ }
+ unset($build['#group_children'][$child]);
+ if (isset($build['#groups'][$parent])) {
+ unset($build['#groups'][$parent]);
+ }
+ }
+ unset($build['#groups'][$dependent]);
+ unset($build['#fieldgroups'][$dependent]);
+}
+
+/**
+ * Helper function to recursively find all progeny of a group.
+ *
+ * To deal with nested groups.
+ *
+ * @param array $elements
+ * Array of all fields and groups that are in a group.
+ * @param array $groups
+ * Array of all groups.
+ * @param string $parent
+ * The parent group for which its children are being sought.
+ *
+ * @return array
+ * Children as keys, and the parent group as the values.
+ */
+function _conditional_fields_get_all_progeny($elements, $groups, $parent) {
+ $children = array();
+ foreach ($elements as $child => $group) {
+ if (in_array($child, $groups)) {
+ $children += _conditional_fields_get_all_progeny($elements, $groups, $child);
+ }
+ if ($group == $parent) {
+ $children[$child] = $group;
+ }
+ }
+ return $children;
+}
+
+/**
* Evaluates an array with 'AND', 'OR' and 'XOR' groupings,
* each containing a list of boolean values.
*/
@@ -1274,7 +1448,7 @@ function conditional_fields_dependency_default_options() {
*
* The result can be filtered by providing an entity type and a bundle name.
*/
-function conditional_fields_load_dependencies($entity_type = NULL, $bundle = NULL) {
+function conditional_fields_load_dependencies($entity_type = NULL, $bundle = NULL, $group_view_mode = 'form') {
// Use the advanced drupal_static() pattern.
static $dependencies;
if (!isset($dependencies)) {
@@ -1291,49 +1465,62 @@ function conditional_fields_load_dependencies($entity_type = NULL, $bundle = NUL
}
$default_options = conditional_fields_dependency_default_options();
+ // Get dependent fields and groupd separately, as which will be 'joined'
+ // depends on the options['group'] value.
+ $dependent_fields_select = db_select('field_config_instance', 'fci')
+ ->fields('fci', array('id', 'field_name'));
+ $dependent_groups_select = db_select('field_group', 'fg')
+ ->fields('fg', array('id', 'group_name'))
+ ->condition('mode', $group_view_mode);
+
$select = db_select('conditional_fields', 'cf')
- ->fields('cf', array('id', 'options'))
- ->orderBy('cf.dependent');
+ ->fields('cf', array('id', 'dependent', 'options'));
$fci_depende = $select->join('field_config_instance', 'fci_dependee', 'cf.dependee = fci_dependee.id');
- $fci_dependent = $select->join('field_config_instance', 'fci_dependent', 'cf.dependent = fci_dependent.id');
$select->addField($fci_depende, 'field_name', 'dependee');
- $select->addField($fci_dependent, 'field_name', 'dependent');
$select->addField($fci_depende, 'entity_type');
$select->addField($fci_depende, 'bundle');
if ($entity_type) {
- $select->condition(
- db_and()
- ->condition('fci_dependee.entity_type', $entity_type)
- ->condition('fci_dependent.entity_type', $entity_type)
- );
+ $dependent_fields_select->condition('fci.entity_type', $entity_type);
+ $dependent_groups_select->condition('fg.entity_type', $entity_type);
+ $select->condition('fci_dependee.entity_type', $entity_type);
}
if ($bundle) {
- $select->condition(
- db_and()
- ->condition('fci_dependee.bundle', $bundle)
- ->condition('fci_dependent.bundle', $bundle)
- );
+ $dependent_fields_select->condition('fci.bundle', $bundle);
+ $dependent_groups_select->condition('fg.bundle', $bundle);
+ $select->condition('fci_dependee.bundle', $bundle);
}
$result = $select->execute();
+ $dependent_fields = $dependent_fields_select->execute()->fetchAllAssoc('id');
+ $dependent_groups = $dependent_groups_select->execute()->fetchAllAssoc('id');
foreach ($result as $dependency) {
$result_entity_type = $entity_type ? $entity_type : $dependency->entity_type;
$result_bundle = $bundle ? $bundle : $dependency->bundle;
$options = unserialize($dependency->options);
+ if (isset($options['group']) && $options['group']) {
+ $dependency->dependent = $dependent_groups[$dependency->dependent]->group_name;
+ $dependency->type = 'group';
+ }
+ else {
+ $dependency->dependent = $dependent_fields[$dependency->dependent]->field_name;
+ $dependency->type = 'field';
+ }
$options += $default_options;
$dependencies[$result_entity_type][$result_bundle]['dependents'][$dependency->dependent][$dependency->id] = array(
'dependee' => $dependency->dependee,
'options' => $options,
+ 'type' => $dependency->type,
);
$dependencies[$result_entity_type][$result_bundle]['dependees'][$dependency->dependee][$dependency->id] = array(
'dependent' => $dependency->dependent,
'options' => $options,
+ 'type' => $dependency->type,
);
}
}
@@ -1928,7 +2115,7 @@ function conditional_fields_states_handler_link_addressfield($field, $field_info
}
/**
- * Build a textual description of a dependency
+ * Build a textual description of a dependency.
*/
function conditional_fields_dependency_description($dependee_name, $dependent_name, $options) {
$states = conditional_fields_states();
diff --git a/includes/conditional_fields.admin.inc b/includes/conditional_fields.admin.inc
index 4e876fe..25c1282 100644
--- a/includes/conditional_fields.admin.inc
+++ b/includes/conditional_fields.admin.inc
@@ -1,4 +1,5 @@
$group) {
+ $groups[$group_name] = (array) $group;
+ }
+ // New merged array of fields & groups for dependents
+ // Dependees should only be fields ($instances)
+ $instances_groups = $instances + $groups;
if (count($instances) < 2) {
$form['no_fields'] = array(
@@ -163,7 +173,7 @@ function conditional_fields_dependency_add_form($form, &$form_state, $entity_typ
// first row they will appear grouped.
if ($first_row == TRUE) {
$form['table']['dependencies'][$id]['dependent'] = array(
- '#markup' => check_plain($instances[$dependent]['label']) . ' (' . $dependent . ')',
+ '#markup' => check_plain($instances_groups[$dependent]['label']) . ' (' . $dependent . ')',
'#rowspan' => $dependee_count,
);
@@ -176,8 +186,8 @@ function conditional_fields_dependency_add_form($form, &$form_state, $entity_typ
),
);
- // To avoid clutter, collect information about groupings so we can show each
- // operator once per dependent.
+ // To avoid clutter, collect information about groupings
+ // so we can show each operator once per dependent.
if ($dependee_count > 1) {
if (${'show_' . $dependency['options']['grouping']}) {
$row['group'] = array(
@@ -191,7 +201,7 @@ function conditional_fields_dependency_add_form($form, &$form_state, $entity_typ
$row['description']['#colspan'] = 2;
}
- $row['description']['#markup'] = conditional_fields_dependency_description($instances[$dependency['dependee']]['label'], $instances[$dependent]['label'], $dependency['options']);
+ $row['description']['#markup'] = conditional_fields_dependency_description($instances[$dependency['dependee']]['label'], $instances_groups[$dependent]['label'], $dependency['options']);
$row['edit'] = array(
'#type' => 'link',
@@ -221,6 +231,15 @@ function conditional_fields_dependency_add_form($form, &$form_state, $entity_typ
asort($fields);
+ // Build list of available groups. Preface each id with a 'g' to avoid
+ // collission with field ids, and to identify it as a group.
+ $fieldgroups = array();
+ foreach ($groups as $group_name => $group) {
+ $fieldgroups['g' . $group['id']] = check_plain($group['label'] . ' (' . $group['group_name'] . ')');
+ }
+
+ asort($fieldgroups);
+
// Build list of states.
$states = array_map('drupal_strtolower', conditional_fields_states());
@@ -236,7 +255,7 @@ function conditional_fields_dependency_add_form($form, &$form_state, $entity_typ
'#title' => t('Dependent'),
'#title_display' => 'invisible',
'#description' => t('Dependent'),
- '#options' => $fields,
+ '#options' => $fields + $fieldgroups,
'#prefix' => '' . t('Add new dependency') . '
',
),
'dependee' => array(
@@ -302,6 +321,12 @@ function conditional_fields_dependency_add_form_submit($form, &$form_state) {
'state' => $form_state['values']['state'],
'condition' => $form_state['values']['condition']
);
+ // Determine if the dependent is a group, and adjust the ID and save the group
+ // indicator in options.
+ if (substr($form_state['values']['dependent'], 0, 1) == 'g') {
+ $options['group'] = TRUE;
+ $form_state['values']['dependent'] = substr($form_state['values']['dependent'], 1);
+ }
if (!$id = conditional_fields_dependency_insert($form_state['values']['dependee'], $form_state['values']['dependent'], $options)) {
drupal_set_message(t('There was an error while trying to create the dependency.'), 'error');
@@ -428,7 +453,7 @@ function conditional_fields_dependency_edit_form($form, &$form_state, $dependenc
CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR => t('Any of these values (OR)...'),
CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR => t('Only one of these values (XOR)...'),
CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT => t('None of these values (NOT)...'),
- // TODO: PHP evaluation
+ // TODO: PHP evaluation.
),
),
'#default_value' => $dependency['options']['values_set'],
@@ -749,7 +774,6 @@ function conditional_fields_dependency_edit_form_submit($form, &$form_state) {
// TODO: validate values against allowed values.
// TODO: unify 'value' and 'values' fields.
-
$dependency = array(
'id' => $form['#dependency']['id'],
'dependee' => $form['#dependency']['dependee'],
@@ -800,6 +824,11 @@ function conditional_fields_dependency_edit_form_submit($form, &$form_state) {
}
}
+ // Save the group indicator in options.
+ if (isset($form['#dependency']['options']['group']) && $form['#dependency']['options']['group']) {
+ $dependency['options']['group'] = $form['#dependency']['options']['group'];
+ }
+
conditional_fields_dependency_update($dependency);
drupal_set_message(t('Saved dependency configuration.'));
}
@@ -819,11 +848,11 @@ function conditional_fields_dependency_delete_form($form, $form_state, $dependen
return confirm_form(
array(
- 'dependency' => array(
- '#type' => 'value',
- '#value' => $dependency['id'],
+ 'dependency' => array(
+ '#type' => 'value',
+ '#value' => $dependency['id'],
+ ),
),
- ),
t('Are you sure you want to delete this dependency?'),
$destination['destination'],
t('This action cannot be undone.'),
diff --git a/includes/conditional_fields.features.inc b/includes/conditional_fields.features.inc
index 24c2885..6fc80d3 100644
--- a/includes/conditional_fields.features.inc
+++ b/includes/conditional_fields.features.inc
@@ -1,4 +1,5 @@
$field_dep_settings) {
if ($dependancy_type == 'dependees' && !empty($field_dep_settings)) {
@@ -111,7 +112,21 @@ function conditional_fields_features_rebuild($module) {
}
$entity_instances = $instances[$field['entity']][$field['bundle']];
$dependee_id = $entity_instances[$field['dependee']]['id'];
- $dependent_id = $entity_instances[$field['dependent']]['id'];
+ $dependent_id = 0;
+ if (array_key_exists($field['dependent'], $entity_instances)) {
+ $dependent_id = $entity_instances[$field['dependent']]['id'];
+ }
+ elseif (module_exists('field_group')) {
+ $entity_groups = field_group_info_groups($field['entity'], $field['bundle'], 'form');
+ if (array_key_exists($field['dependent'], $entity_groups)) {
+ if (!$entity_groups[$field['dependent']]->id) {
+ field_group_group_save($entity_groups[$field['dependent']]);
+ $identifier = $entity_groups[$field['dependent']]->identifier;
+ $entity_groups[$field['dependent']] = field_group_load_field_group_by_identifier($identifier);
+ }
+ $dependent_id = $entity_groups[$field['dependent']]->id;
+ }
+ }
conditional_fields_dependency_insert($dependee_id, $dependent_id, $field['options']);
}
}