You are here

function fieldgroup_form_alter in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
  2. 6 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
  3. 6.2 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()

File

./fieldgroup.module, line 289
Create field groups for CCK fields.

Code

function fieldgroup_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
    foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) {
      $form[$group_name] = array(
        '#type' => 'fieldset',
        '#title' => check_plain(t($group['label'])),
        '#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed',
        '#collapsible' => in_array($group['settings']['form']['style'], array(
          'fieldset_collapsed',
          'fieldset_collapsible',
        )),
        '#weight' => $group['weight'],
        '#description' => content_filter_xss(t($group['settings']['form']['description'])),
        '#attributes' => array(
          'class' => strtr($group['group_name'], '_', '-'),
        ),
      );
      foreach ($group['fields'] as $field_name => $field) {
        if (isset($form[$field_name])) {
          $form[$group_name][$field_name] = $form[$field_name];
          unset($form[$field_name]);
        }
      }
      if (!empty($group['fields']) && !element_children($form[$group_name])) {

        //hide the fieldgroup, because the fields are hidden too
        unset($form[$group_name]);
      }
    }
  }
  else {
    if ($form_id == '_content_admin_field') {
      $content_type = content_types($form['type_name']['#value']);
      $form['widget']['group'] = array(
        '#type' => 'select',
        '#title' => t('Display in group'),
        '#options' => _fieldgroup_groups_label($content_type['type']),
        '#default_value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']),
        '#description' => t('Select a group, in which the field will be displayed on the editing form.'),
        '#weight' => 5,
      );
      $form['widget']['weight']['#weight'] = 5;
      $form['widget']['description']['#weight'] = 7;
      $form['#submit']['fieldgroup_content_admin_form_submit'] = array(
        $form['widget']['group']['#default_value'],
      );
    }
    else {
      if ($form_id == 'content_admin_display_overview_form') {
        $form['groups'] = fieldgroup_display_overview_form($form['type_name']['#value']);
        $form['groups']['#theme'] = 'fieldgroup_display_overview_form';
        $form['#submit']['fieldgroup_display_overview_form_submit'] = array();
        if (!is_array($form['submit']) && count(fieldgroup_groups($form['type_name']['#value']))) {
          $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Submit'),
            '#weight' => 10,
          );
        }
      }
      else {
        if ($form_id == '_content_admin_field_remove') {
          $form['#submit']['fieldgroup_content_admin_field_remove_submit'] = array();
        }
      }
    }
  }
}