function _field_group_table_row_build

7.x-1.x field_group_table.module _field_group_table_row_build($variables)

Builds a table row for rendering.

1 call to _field_group_table_row_build()
theme_field_group_table_wrapper in ./field_group_table.module
Returns HTML for a field_group_table_wrapper.

File

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

Code

function _field_group_table_row_build($variables) {
  // Merge defaults.
  $variables += array(
    'row_class' => array(),
    'content_attributes' => array(),
  );

  $row = array(
    'data' => array(),
    'no_striping' => !$variables['settings']['table_row_striping'],
    'class' => $variables['row_class'],
  );

  switch ($variables['mode']) {
    case 'display':
      // In some cases (like with field extra fields) #title and #label_display
      // may not be set. In that case we try to use #label as the title instead,
      // as that is commonly used.
      $title = '';
      if (isset($variables['element']['#title'])) {
        $title = $variables['element']['#title'];
      }
      elseif (isset($variables['element']['#label'])) {
        $title = $variables['element']['#label'];
      }
      $label_display = isset($variables['element']['#label_display']) ? isset($variables['element']['#label_display']) : 'above';

      // Display the label in the first column, if 'always show field label' is
      // set.
      if ($variables['settings']['always_show_field_label']) {
        $row['data'][] = array(
          'data' => $title,
          'header' => TRUE,
          'class' => array('field-label'),
        );
      }
      // Display the label in the first column, if it's set to "above" and the
      // title isn't empty.
      elseif ($label_display == 'above' && $title != '') {
        $row['data'][] = array(
          'data' => $title,
          'header' => TRUE,
          'class' => array('field-label'),
        );

        // Do not display the label in the second column.
        $variables['element']['#label_display'] = 'hidden';
      }
      // Display an empty cell if we won't display the title and 'empty label
      // behavior' is set to keep empty label cells.
      elseif ($variables['settings']['empty_label_behavior'] == FIELD_GROUP_TABLE_EMPTY_LABEL_KEEP) {
        $row['data'][] = array(
          'data' => ' ',
          'header' => TRUE,
          'class' => array('field-label', 'field-label-hidden'),
        );
      }
      // Otherwise we merge the cells.
      else {
        $variables['content_attributes']['colspan'] = 2;
      }

      break;

    case 'form':
      $class = array('field-label');

      // Attempt to find a title we can use.
      $title = '';
      if (isset($variables['element']['#title'])) {
        $title = $variables['element']['#title'];
        $required = $variables['element']['#required'];

        $variables['element']['#title'] = '';
        $variables['element']['#required'] = FALSE;
      }
      elseif (isset($variables['element']['#language']) && isset($variables['element'][$variables['element']['#language']]['#title'])) {
        $title = $variables['element'][$variables['element']['#language']]['#title'];
        $required = $variables['element'][$variables['element']['#language']]['#required'];

        $variables['element'][$variables['element']['#language']]['#title'] = '';
        $variables['element'][$variables['element']['#language']]['#required'] = FALSE;
      }
      elseif (isset($variables['element']['#language']) && isset($variables['element'][$variables['element']['#language']][0]['#title'])) {
        $title = $variables['element'][$variables['element']['#language']][0]['#title'];
        $required = $variables['element'][$variables['element']['#language']][0]['#required'];

        $variables['element'][$variables['element']['#language']][0]['#title'] = '';
        $variables['element'][$variables['element']['#language']][0]['#required'] = FALSE;
      }

      if ($title != '' || ($title == '' && $variables['settings']['empty_label_behavior'] == FIELD_GROUP_TABLE_EMPTY_LABEL_KEEP)) {
        $row['data'][] = array(
          'data' => ($title == '') ? ' ' : array(
            '#type' => 'item',
            '#title' => $title,
            '#required' => $required,
          ),
          'header' => TRUE,
          'class' => $class,
        );
      }
      else {
        $variables['content_attributes']['colspan'] = 2;
      }

      break;
  }

  // Add the field's content.
  $row['data'][] = $variables['content_attributes'] + array(
    'data' => $variables['element'],
    'class' => array('field-content'),
  );

  return $row;
}