You are here

function content_admin_display_overview_form in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 content_admin.inc \content_admin_display_overview_form()

Menu callback; presents a listing of fields display settings for a content type.

Form includes form widgets to select which fields appear for teaser, full node and how the field labels should be rendered.

2 string references to 'content_admin_display_overview_form'
content_menu in ./content.module
Implementation of hook_menu().
fieldgroup_form_alter in modules/fieldgroup/fieldgroup.module

File

includes/content.admin.inc, line 235
Administrative interface for content type creation.

Code

function content_admin_display_overview_form(&$form_state, $type_name, $contexts_selector = CONTENT_CONTEXTS_SIMPLE) {

  // Gather type information.
  $type = content_types($type_name);
  $field_types = _content_field_types();

  // TODO : needed ?
  $fields = $type['fields'];
  if (empty($fields)) {
    drupal_set_message(t('There are no fields configured for this content type. You can !link.', array(
      '!link' => l(t('Add a new field'), str_replace('/fields', '/add_field', $_GET['q'])),
    )), 'warning');
    return array();
  }
  $groups = $group_options = array();
  if (module_exists('fieldgroup')) {
    $groups = fieldgroup_groups($type['type']);
    $group_options = _fieldgroup_groups_label($type['type']);
  }
  $contexts = _content_admin_display_contexts($contexts_selector);

  // Rows in this table are essentially nested, but for the simplicity of
  // theme and submit functions, we keep them in a flat array, and use a
  // $dummy render structure to figure the right display order.
  $dummy = array();
  $form = array(
    '#tree' => TRUE,
    '#type_name' => $type['type'],
    '#fields' => array_keys($fields),
    '#groups' => array_keys($groups),
    '#contexts' => $contexts_selector,
    '#order' => array(),
  );

  // Fields.
  $label_options = array(
    'above' => t('Above'),
    'inline' => t('Inline'),
    'hidden' => t('<Hidden>'),
  );
  foreach ($fields as $name => $field) {
    $field_type = $field_types[$field['type']];
    $defaults = $field['display_settings'];
    $weight = $field['widget']['weight'];
    $form[$name] = array(
      'human_name' => array(
        '#value' => $field['widget']['label'],
      ),
    );

    // Label
    if ($contexts_selector == CONTENT_CONTEXTS_SIMPLE) {
      $form[$name]['label']['format'] = array(
        '#type' => 'select',
        '#options' => $label_options,
        '#default_value' => isset($defaults['label']['format']) ? $defaults['label']['format'] : 'above',
      );
    }

    // Formatters.
    $options = array();
    foreach ($field_type['formatters'] as $formatter_name => $formatter_info) {
      $options[$formatter_name] = $formatter_info['label'];
    }
    $options['hidden'] = t('<Hidden>');
    foreach ($contexts as $key => $title) {
      $form[$name][$key]['format'] = array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'default',
      );
    }
    $dummy[$name] = array(
      '#weight' => $weight,
      '#value' => $name . ' ',
    );
  }

  // Groups.
  $label_options = array(
    'above' => t('Above'),
    'hidden' => t('<Hidden>'),
  );
  $options = array(
    'no_style' => t('no styling'),
    'simple' => t('simple'),
    'fieldset' => t('fieldset'),
    'fieldset_collapsible' => t('fieldset - collapsible'),
    'fieldset_collapsed' => t('fieldset - collapsed'),
    'hidden' => t('<Hidden>'),
  );
  foreach ($groups as $name => $group) {
    $defaults = $group['settings']['display'];
    $weight = $group['weight'];
    $form[$name] = array(
      'human_name' => array(
        '#value' => $group['label'],
      ),
    );
    $form[$name]['label'] = array(
      '#type' => 'select',
      '#options' => $label_options,
      '#default_value' => isset($defaults['label']) ? $defaults['label'] : 'above',
    );
    foreach ($contexts as $key => $title) {
      $form[$name][$key]['format'] = array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => isset($defaults[$key]) ? $defaults[$key] : 'fieldset',
      );
    }
    $dummy[$name] = array(
      '#weight' => $weight,
      '#value' => $name . ' ',
    );

    // Adjust child fields rows.
    foreach ($group['fields'] as $field_name => $field) {
      $form[$field_name]['#depth'] = 1;
      $dummy[$name][$field_name] = $dummy[$field_name];
      unset($dummy[$field_name]);
    }
  }

  // Let drupal_render figure out the right order for the rows.
  $form['#order'] = explode(' ', trim(drupal_render($dummy)));
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}