function content_field_replace in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6 includes/content.admin.inc \content_field_replace()
- 6.2 includes/content.admin.inc \content_field_replace()
Content Field Replace
Replace field values in a node from an array of update values.
Supply an array of one or more fields and masks of field column values to be replaced into field values, one mask for basic values and an optional different mask for values in field items equal to or higher than a specified delta.
The masks should contain only the column values to be substituted in. The supplied values will be merged into the existing values to replace only the values in the mask, leaving all other values unchanged.
The ability to set different masks starting at a delta allows the possibility of setting values above a certain delta to NULL prior to altering the database schema.
Parameters
$nid:
$updates: an array like: 'field_name' => array( 'mask' => array() // Keyed array of column names and replacement values for use // below delta, or for all values if no delta is supplied. 'alt_mask' => array() // Optional, keyed array of column names and replacement values for use // at or above delta, if a delta is supplied. 'delta' => # // Optional, the number to use as the delta value where you switch from // one mask to the other. ),
1 call to content_field_replace()
- content_field_batch_update in includes/
content.admin.inc - Content Field Batch Update Operation
File
- includes/
content.admin.inc, line 1914 - Administrative interface for content type creation.
Code
function content_field_replace($nid, $updates) {
$node = node_load($nid, NULL, TRUE);
foreach ($updates as $field_name => $update) {
$items = isset($node->{$field_name}) ? $node->{$field_name} : array();
foreach ($items as $delta => $value) {
$field_mask = isset($update['delta']) && isset($update['alt_mask']) && $delta >= $update['delta'] ? $update['alt_mask'] : $mask['mask'];
// Merge the mask into the field values to do the replacements.
$items[$delta] = array_merge($items[$delta], $field_mask);
}
// Test if the new values will make items qualify as empty.
$items = content_set_empty($field, $items);
$node->{$field_name} = $items;
}
node_save($node);
return $node;
}