field_attach_update
- Versions
- 7
field_attach_update($obj_type, $object)
Save field data for an existing object.
Parameters
$obj_type The type of $object; e.g. 'node' or 'user'.
$object The object with fields to save.
Related topics
Code
modules/field/field.attach.inc, line 864
<?php
function field_attach_update($obj_type, $object) {
_field_invoke('update', $obj_type, $object);
list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object);
// Let any module update field data before the storage engine, accumulating
// saved fields along the way.
$skip_fields = array();
foreach (module_implements('field_storage_pre_update') as $module) {
$function = $module . '_field_storage_pre_update';
$function($obj_type, $object, $skip_fields);
}
// Collect the storage backends used by the remaining fields in the objects.
$storages = array();
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_name = $field['field_name'];
// Leave the field untouched if $object comes with no $field_name property,
// but empty the field if it comes as a NULL value or an empty array.
// Function property_exists() is slower, so we catch the more frequent
// cases where it's an empty array with the faster isset().
if (isset($object->$field_name) || property_exists($object, $field_name)) {
// Collect the storage backend if the field has not been written yet.
if (!isset($skip_fields[$field_id])) {
$storages[$field['storage']['type']][$field_id] = $field_id;
}
}
}
// Field storage backends save any remaining unsaved fields.
foreach ($storages as $storage => $fields) {
$storage_info = field_info_storage_types($storage);
module_invoke($storage_info['module'], 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $fields);
}
// Let other modules act on updating the object.
module_invoke_all('field_attach_update', $obj_type, $object);
if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field');
}
}
?>Login or register to post comments 