You are here

function conditional_fields_form_alter in Conditional Fields 6.2

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 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 277
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 (!isset($form_state['clicked_button']) || $form_state['clicked_button']['#parents'][0] != 'change') {
        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
      foreach ($form as $item_name => $item) {
        if (db_result(db_query("SELECT COUNT(*) FROM {conditional_fields} WHERE field_name = '%s'", $item_name))) {
          $form[$item_name]['#post_render'] = array_merge(array(
            'conditional_fields_add_more_post_render',
          ), (array) $form[$item_name]['#post_render']);
          foreach (element_children($form[$item_name]) as $element) {
            conditional_fields_custom_required_field($form[$item_name][$element], $form['#field_info'][$item_name]);
          }
        }
      }
      break;
    case 'content_copy_import_form':
      $form['#submit'][] = 'conditional_fields_import';
      break;

    // Compatibility with Content Profile User Registration module.
    case 'user_register':
      if (isset($form['#content_profile_registration_use_types'])) {
        conditional_fields_node_form($form, $form_state);
      }
      break;
  }
  if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] . '_node_form') {
    conditional_fields_node_form($form, $form_state);
  }
}