diff --git a/conditional_fields.module b/conditional_fields.module index d8f11c3..da0a612 100755 --- a/conditional_fields.module +++ b/conditional_fields.module @@ -308,6 +308,9 @@ function conditional_fields_form_alter(&$form, $form_state, $form_id) { case 'content_copy_import_form': $form['#submit'][] = 'conditional_fields_import'; break; + case 'user_register': + conditional_fields_node_editing_form($form, $form_state); + break; } if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] . '_node_form') { @@ -642,8 +645,41 @@ function conditional_fields_node_after_build($form, &$form_state) { return $form; } - $type_name = $form['type']['#value']; + // Find all content profile types used in this form + $form_ctypes = (array_key_exists('#content_profile_registration_use_types', $form) && is_array($form['#content_profile_registration_use_types'])) ? + array_keys($form['#content_profile_registration_use_types']) : array($form['type']['#value']); + + $ui_settings_type = NULL; + foreach($form_ctypes as $form_ctype) { + // Update the form & js settings for each content profile type + $form = conditional_fields_node_type_after_build($form, $form_state, $form_ctype, $js_settings); + // Use the user interface settings of the first content profile that has them. + if (! $ui_settings_type && variable_get('c_fields_js_' . $form_ctype, NULL)) + $ui_settings_type = $form_ctype; + } + + // Hopefully, we found out above which content type has UI settings. Now, we'll use them. + $ui_settings = variable_get('c_fields_js_' . $ui_settings_type, C_FIELDS_JS_HIDE); + switch ($ui_settings) { + case C_FIELDS_JS_DISABLE: + $js_settings['ui_settings'] = 'disable'; + break; + case C_FIELDS_JS_HIDE: + $js_settings['ui_settings']['animation'] = (int)variable_get('c_fields_animation_' . $ui_settings_type, C_FIELDS_ANIMATION_NO); + $js_settings['ui_settings']['anim_speed'] = variable_get('c_fields_anim_speed_' . $ui_settings_type, "normal"); + break; + } + + if ($ui_settings != C_FIELDS_JS_NO) { + conditional_fields_add_js($js_settings); + } + + $form['#conditional_fields']['settings'] = $js_settings; + + return $form; +} +function conditional_fields_node_type_after_build($form, &$form_state, $type_name, &$js_settings) { // Do nothing if there are no conditional fields if (!$data = conditional_fields_load_data($type_name)) { return $form; @@ -776,26 +812,10 @@ function conditional_fields_node_after_build($form, &$form_state) { } } - // Apply user interface settings - $ui_settings = variable_get('c_fields_js_' . $type_name, C_FIELDS_JS_HIDE); - switch ($ui_settings) { - case C_FIELDS_JS_DISABLE: - $js_settings['ui_settings'] = 'disable'; - break; - case C_FIELDS_JS_HIDE: - $js_settings['ui_settings']['animation'] = (int)variable_get('c_fields_animation_' . $type_name, C_FIELDS_ANIMATION_NO); - $js_settings['ui_settings']['anim_speed'] = variable_get('c_fields_anim_speed_' . $type_name, "normal"); - break; - } - - if ($ui_settings != C_FIELDS_JS_NO) { - conditional_fields_add_js($js_settings); - } // Pass variables for validation $form['#conditional_fields']['data'] = $data; $form['#conditional_fields']['required_fields'] = $required_fields; - $form['#conditional_fields']['settings'] = $js_settings; // Add validation function $form['#validate'] = array_merge(array('conditional_fields_node_editing_form_validate'), (array)$form['#validate']); @@ -933,7 +953,7 @@ function conditional_fields_node_editing_form_validate($form, &$form_state) { } else { // Do not submit values of controlled fields which were not triggered (except on preview) - if (variable_get('c_fields_reset_default_' . $form['type']['#value'], 1) + if (variable_get('c_fields_reset_default_' . $type_name, 1) && !in_array('node_form_build_preview', (array)$form_state['submit_handlers'])) { // Load default values like in content_field_form() in content.node_form.inc $controlled_field_info = $form['#field_info'][$controlled_field_name]; @@ -964,8 +984,8 @@ function conditional_fields_node_editing_form_validate($form, &$form_state) { } else { // Do not submit values of controlled fields which were not triggered (except on preview) - if (variable_get('c_fields_reset_default_' . $form['type']['#value'], 1) && - !isset($form_state['node_preview'])) { + if (variable_get('c_fields_reset_default_' . $type_name, 1) && + !in_array('node_form_build_preview', (array)$form_state['submit_handlers'])) { // Load default values like in content_field_form() in content.node_form.inc $field_in_group_info = $form['#field_info'][$field_in_group]; if (content_callback('widget', 'default value', $field_in_group_info) != CONTENT_CALLBACK_NONE) {