You are here

function content_set_empty in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 content.module \content_set_empty()
  2. 6.2 content.module \content_set_empty()

Helper function to set NULL values and unset items where needed.

If a specified number of multiple values was requested or this is the zero delta, save even if empty and keep a NULL value for each of its columns so there is a marker row in the database, otherwise unset the item.

Parameters

array $field:

array $items:

Return value

array returns emptied and adjusted item array

2 calls to content_set_empty()
content_field in ./content.module
Implementation of hook_field(). Handles common field housekeeping.
content_field_replace in includes/content.admin.inc
Content Field Replace

File

./content.module, line 789
Allows administrators to associate custom fields to content types.

Code

function content_set_empty($field, $items) {
  $function = $field['module'] . '_content_is_empty';
  $max_delta = $field['multiple'] > 1 ? $field['multiple'] : 0;
  foreach ((array) $items as $delta => $item) {
    if ($function($item, $field)) {
      if ($delta <= $max_delta) {
        foreach (array_keys($field['columns']) as $column) {
          $items[$delta][$column] = NULL;
        }
      }
      else {
        unset($items[$delta]);
      }
    }
  }
  return $items;
}