You are here

function conditional_fields_form_alter in Conditional Fields 6

Same name and namespace in other branches
  1. 8 conditional_fields.module \conditional_fields_form_alter()
  2. 5 conditional_fields.module \conditional_fields_form_alter()
  3. 6.2 conditional_fields.module \conditional_fields_form_alter()
  4. 4.x conditional_fields.module \conditional_fields_form_alter()

Implementation of hook_form_alter().

File

./conditional_fields.module, line 275
Content fields and groups visibility based on the values of user defined 'trigger' fields.

Code

function conditional_fields_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'content_field_edit_form':
      if ($form['widget'] && $form_state['post']['op'] != t('Change basic information')) {
        conditional_fields_content_admin_field($form);
      }
      break;
    case 'fieldgroup_group_edit_form':
      conditional_fields_fieldgroup_group_edit_form($form);
      break;
    case 'content_field_overview_form':

      // Find conditional fields, mark them, and disable group select for them
      $conditional_fields = conditional_fields_field_overview_form($form);
      break;
    case '_content_admin_field_remove':
      $form['#submit'] = $form['#submit'] + array(
        '_conditional_fields_content_admin_field_remove_submit' => array(),
      );
      break;
    case 'fieldgroup_remove_group':
      $form['#submit'][] = 'conditional_fields_fieldgroup_remove_group_submit';
      break;
    case 'content_add_more_js':

      // Handle ahah multiple fields
      $key = array_keys($form);
      if (db_result(db_query("SELECT COUNT(*) FROM {conditional_fields} WHERE field_name = '%s'", $key[0]))) {
        $form[$key[0]]['#prefix'] .= '<div id="conditional-' . conditional_fields_form_clean_id($key[0]) . '" class="conditional-field controlled-field">';
        $form[$key[0]]['#suffix'] = $form[$key[0]]['#suffix'] . '</div>';
        foreach (element_children($form[$key[0]]) as $element) {
          conditional_fields_unset_required_field($form[$key[0]][$element]);
        }
      }
      break;
    case 'content_copy_import_form':
      $form['#submit'][] = 'conditional_fields_import';
      break;
  }
  if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] . '_node_form') {
    conditional_fields_node_editing_form($form, $form_state);
  }
}