You are here

function content_type_groups_group_form in Content type groups 7

Same name and namespace in other branches
  1. 7.2 content_type_groups.admin.inc \content_type_groups_group_form()

Form builder; Returns form for adding a new content type group.

See also

user_filter_form_submit()

1 string reference to 'content_type_groups_group_form'
content_type_groups_menu in ./content_type_groups.module
Implements hook_menu().

File

./content_type_groups.admin.inc, line 46
Admin page callback file for the Content type groups module.

Code

function content_type_groups_group_form($form, &$form_state, $group = NULL) {

  // If editing an existing group, get its info
  $locked = (bool) $group;
  $group = new ContentTypeGroup($group);

  // Display name for admin interface
  $form['name'] = array(
    '#title' => t('Name'),
    '#type' => 'textfield',
    '#default_value' => $group->name,
    '#description' => t('The human-readable name of this content type group. This text will be displayed as part of the list on the <em>Add new content type group</em> page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
    '#required' => TRUE,
    '#size' => 30,
  );

  // Machine name for referencing in Views/Features
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => $group->type,
    '#disabled' => $locked,
    '#description' => t('A unique machine-readable name for this content type group. It must only contain lowercase letters, numbers, and underscores. This name will be used for referencing this content type group, in which underscores will be converted into hyphens.'),
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'content_type_groups_group_load',
    ),
  );

  // Build a table tree of the existing content types
  $form['items'] = array(
    '#tree' => TRUE,
  );

  // Create a list of sortable content types, sorted by weight
  $existing_types = $group
    ->typeList(TRUE);
  $all_types = node_type_get_names();
  foreach ($existing_types as $machine_name => $data) {
    $form['content_types'][$machine_name] = array(
      'checked-' . $machine_name => array(
        '#type' => 'checkbox',
        '#default_value' => 1,
        '#attributes' => array(
          'class' => array(
            'check',
          ),
        ),
      ),
      'name' => array(
        '#markup' => $data['name'],
      ),
      'weight-' . $machine_name => array(
        '#type' => 'weight',
        '#delta' => count($all_types) + 1,
        '#default_value' => $existing_types[$machine_name]['weight'],
        '#attributes' => array(
          'class' => array(
            'weight',
          ),
        ),
      ),
    );
    unset($all_types[$machine_name]);
  }
  $last_type = end($existing_types);
  $last_weight = $last_type['weight'];
  foreach ($all_types as $machine_name => $name) {
    $last_weight++;
    $form['content_types'][$machine_name] = array(
      'checked-' . $machine_name => array(
        '#type' => 'checkbox',
        '#default_value' => 0,
        '#attributes' => array(
          'class' => array(
            'check',
          ),
        ),
      ),
      'name' => array(
        '#markup' => $name,
      ),
      'weight-' . $machine_name => array(
        '#type' => 'weight',
        '#delta' => count($all_types) + 1,
        '#default_value' => $last_weight,
        '#attributes' => array(
          'class' => array(
            'weight',
          ),
        ),
      ),
    );
  }

  // Add the subgroup fields

  /*
  $form['subgroup'] = array(
    'checked' => array(
      '#type'          => 'hidden',
      '#default_value' => 0,
      '#attributes'    => array('class' => array('check')),
    ),
    'name' => array(
      '#type'    => 'select',
      '#title'   => t('Add subgroup'),
      '#options' => array_merge(array('' => t('- Select a content type -')), ContentTypeGroup::fetch()),
    ),
    'weight' => array(
      '#type'          => 'weight',
      '#delta'         => count($existing_types) + 1,
      '#default_value' => count($existing_types) + 1,
      '#attributes'    => array('class' => array('weight')),
    ),

  );
  */

  // Action buttons
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['delete'] = array(
    '#type' => 'button',
    '#value' => t('Delete'),
  );
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), 'admin/structure/types/groups'),
  );
  return $form;
}