You are here

function _paragraphs_table_hide_empty in Paragraphs table 7

Remove columns that are entirely empty.

1 call to _paragraphs_table_hide_empty()
paragraphs_table_field_formatter_view in ./paragraphs_table.module
Implements hook_field_formatter_view().

File

./paragraphs_table.module, line 377
Module file for Paragraph table module.

Code

function _paragraphs_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]);
      }
    }
  }
}