You are here

function tablefield_field_is_empty in TableField 7.3

Same name and namespace in other branches
  1. 7 tablefield.module \tablefield_field_is_empty()
  2. 7.2 tablefield.module \tablefield_field_is_empty()

Implements hook_field_is_empty().

1 call to tablefield_field_is_empty()
tablefield_field_validate in ./tablefield.module
Implements hook_field_validate().

File

./tablefield.module, line 561
Provides a set of fields that can be used to store tabular data with a node.

Code

function tablefield_field_is_empty($item, $field) {

  // @todo, is this the best way to mark the default value form?
  // if we don't, it won't save the number of rows/cols
  // Allow the system settings form to have an emtpy table
  if (arg(0) == 'admin') {
    return FALSE;
  }

  // Check for already serialized data. This is the case for other language
  // versions of this field.
  if (!empty($item['tabledata'])) {
    return FALSE;
  }
  $count_rows = $item['tablefield']['rebuild']['count_rows'];

  // Remove the preference fields to see if the table cells are all empty.
  unset($item['tablefield']['caption']);
  unset($item['tablefield']['rebuild']);
  unset($item['tablefield']['import']);
  unset($item['tablefield']['paste']);
  if (!empty($item['tablefield']['tabledata'])) {
    for ($i = 0; $i < $count_rows; $i++) {
      foreach ($item['tablefield']['tabledata']["row_{$i}"] as $key => $cell) {

        // Keys denoting weight data and anything still iterateable should be
        // ignored while checking for empty cell data.
        if (strpos($key, 'weight') === FALSE && !is_array($cell) && !empty($cell)) {
          return FALSE;
        }
      }
    }
  }
  return TRUE;
}