function field_group_table_field_group_format_settings

7.x-1.x field_group_table.module field_group_table_field_group_format_settings($group)

Implements hook_field_group_format_settings().

File

./field_group_table.module, line 76
Adds a "Table" format to Field Groups.

Code

function field_group_table_field_group_format_settings($group) {
  // Add a wrapper for extra settings to use by others.
  $form = array(
    'instance_settings' => array(
      '#tree' => TRUE,
      '#weight' => 2,
    ),
  );

  $field_group_types = field_group_formatter_info();
  $mode = $group->mode == 'form' ? 'form' : 'display';
  $formatter = $field_group_types[$mode][$group->format_type];
  $settings = $group->format_settings['instance_settings'];

  // Add optional instance_settings.
  switch ($group->format_type) {
    case 'table':
      $form['instance_settings']['label_visibility'] = array(
        '#title' => t('Label visibility'),
        '#description' => t('This option determines how to display the Field group label and description.'),
        '#type' => 'select',
        '#options' => array(
          FIELD_GROUP_TABLE_LABEL_HIDDEN => t('Hidden'),
          FIELD_GROUP_TABLE_LABEL_ABOVE => t('Above table'),
          FIELD_GROUP_TABLE_LABEL_CAPTION => t('Table caption'),
        ),
        '#default_value' => isset($settings['label_visibility']) ? $settings['label_visibility'] : $formatter['instance_settings']['label_visibility'],
      );
      $form['instance_settings']['desc'] = array(
        '#title' => t('Description for the group.'),
        '#type' => 'textarea',
        '#default_value' => isset($settings['desc']) ? $settings['desc'] : $formatter['instance_settings']['desc'],
      );
      $form['instance_settings']['first_column'] = array(
        '#title' => t('First column header'),
        '#description' => t('Use this field to add a table header.'),
        '#type' => 'textfield',
        '#default_value' => isset($settings['first_column']) ? $settings['first_column'] : $formatter['instance_settings']['first_column'],
      );
      $form['instance_settings']['second_column'] = array(
        '#title' => t('Second column header'),
        '#description' => t('Use this field to add a table header.'),
        '#type' => 'textfield',
        '#default_value' => isset($settings['second_column']) ? $settings['second_column'] : $formatter['instance_settings']['second_column'],
      );
      $form['instance_settings']['empty_label_behavior'] = array(
        '#title' => t('Empty label behavior'),
        '#type' => 'select',
        '#options' => array(
          FIELD_GROUP_TABLE_EMPTY_LABEL_KEEP => t('Keep empty label cell'),
          FIELD_GROUP_TABLE_EMPTY_LABEL_MERGE => t('Merge cells'),
        ),
        '#default_value' => isset($settings['empty_label_behavior']) ? $settings['empty_label_behavior'] : $formatter['instance_settings']['empty_label_behavior'],
      );
      $form['instance_settings']['table_row_striping'] = array(
        '#title' => t('Table row striping'),
        '#description' => t('Adds zebra striping on the table rows.'),
        '#type' => 'checkbox',
        '#default_value' => isset($settings['table_row_striping']) ? $settings['table_row_striping'] : $formatter['instance_settings']['table_row_striping'],
      );
      $form['instance_settings']['always_show_field_label'] = array(
        '#title' => t('Always show field label'),
        '#description' => t('Forces the field label to always display in the first column and renders the field normally.'),
        '#type' => 'checkbox',
        '#default_value' => isset($settings['always_show_field_label']) ? $settings['always_show_field_label'] : $formatter['instance_settings']['always_show_field_label'],
      );

      break;
  }

  return $form;
}