function field_group_table_field_group_pre_render

7.x-1.x field_group_table.module field_group_table_field_group_pre_render(&$element, $group, &$form)

Implements hook_field_group_pre_render().

File

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

Code

function field_group_table_field_group_pre_render(&$element, $group, &$form) {
  // We only process the 'table' group type.
  if ($group->format_type != 'table') {
    return;
  }

  $view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form';
  $mode = $group->mode == 'form' ? 'form' : 'display';
  $settings = $group->format_settings['instance_settings'];
  $label = check_plain($group->label);

  // Build the caption and description of this group.
  $caption = array();
  if ($settings['label_visibility'] == FIELD_GROUP_TABLE_LABEL_ABOVE) {
    $caption = array(
      '#type' => 'item',
      '#title' => $label,
      '#description' => field_filter_xss($settings['desc']),
    );
  }

  // Build the table header if necessary.
  $header = array();
  if ($settings['first_column'] || $settings['second_column']) {
    $header = array(
      check_plain($settings['first_column']),
      check_plain($settings['second_column']),
    );
  }

  // Create the element.
  $element += array(
    '#theme' => 'field_group_table_wrapper',
    '#title' => $group->label,
    '#mode' => $mode,
    '#groups' => array_keys($form['#groups']),
    '#settings' => $settings,
    '#attributes' => array(
      'class' => array_merge(array('field-group-table', $group->group_name), explode(' ', $settings['classes'])),
    ),
    '#caption' => $caption,
    
    // We will add the table rows upon rendering, as doing it here means
    // messing up the field group hierarchy, which causes issues.
    '#field_group_table' => array(
      '#theme' => "table__field_group_table__$group->group_name",
      '#header' => $header,
      '#caption' => ($settings['label_visibility'] == FIELD_GROUP_TABLE_LABEL_CAPTION) ? $label : NULL,
      '#attributes' => array(
        'class' => array('field-group-format', $group->group_name),
      ),
    ),
  );
}