You are here

function multifield_item_serialize in Multifield 7

Same name and namespace in other branches
  1. 7.2 multifield.module \multifield_item_serialize()
3 string references to 'multifield_item_serialize'
multifield_field_insert in ./multifield.field.inc
Implements hook_field_insert().
multifield_field_presave in ./multifield.field.inc
Implements hook_field_presave().
multifield_field_update in ./multifield.field.inc
Implements hook_field_update().

File

./multifield.module, line 423

Code

function multifield_item_serialize(&$item, $delta, $machine_name) {

  // Serialize the multifield values into separate columns for saving into the
  // field table.
  foreach (multifield_type_get_subfields($machine_name) as $subfield_name) {
    $subfield = field_info_field($subfield_name);
    foreach ($subfield['columns'] as $column => $details) {

      // If the subfield is empty, skip it.
      if (empty($item[$subfield_name][LANGUAGE_NONE][0])) {
        unset($item[$subfield_name . '_' . $column]);
        continue;
      }

      // @see field_sql_storage_field_storage_write()
      // @todo Should this be using array_key_exists() instead of isset()?
      if (!isset($item[$subfield_name][LANGUAGE_NONE][0][$column])) {
        $item[$subfield_name][LANGUAGE_NONE][0][$column] = isset($details['default']) ? $details['default'] : NULL;
      }

      // We need to assign this value by reference because
      // $items[$delta][$subfield_name] could be modified in
      // multifield_field_insert() or multifield_field_update().
      $item[$subfield_name . '_' . $column] =& $item[$subfield_name][LANGUAGE_NONE][0][$column];
    }
  }
}