You are here

function _field_collection_table_hide_empty in Field Collection Table 7

Remove columns that are entirely empty.

1 call to _field_collection_table_hide_empty()
template_preprocess_table__field_collection_table in theme/theme.inc
Preprocess variables for a field collection table.

File

theme/theme.inc, line 185

Code

function _field_collection_table_hide_empty(&$variables) {
  $rows = $variables['rows'];
  $count = array();
  foreach ($rows as $row_delta => $row) {
    foreach ($row['data'] as $column_delta => $column) {
      if (!isset($count[$column_delta])) {
        $count[$column_delta] = 0;
      }
      if (isset($column['data']['#empty'])) {
        $count[$column_delta]++;
      }
    }
  }
  foreach ($count as $column_delta => $column) {
    if ($column === count($rows)) {
      foreach ($rows as $row_delta => $row) {
        unset($variables['rows'][$row_delta]['data'][$column_delta]);
        unset($variables['header'][$column_delta]);
      }
    }
  }
}