function rb_cck_action_set_multiple_values in Rules Bonus Pack 6
Action for 'rb_cck_action_set_multiple_values'.
File
- ./
rb_cck.module, line 742 - Functions for extending CCK field management with Rules.
Code
function rb_cck_action_set_multiple_values($node, $settings) {
// Get required metadata for the field.
$storage_key = rb_cck_field_storage_key($settings['field']);
// If we should replace the existing field values, remove the existing ones
// first. Then we set it to an empty array to have the foreach below work.
if ($settings['replace']) {
unset($node->{$settings['field']});
$node->{$settings['field']} = array();
}
// Loop through all the supplied values.
foreach (explode("\r", $settings['values']) as $value) {
// Check if the value is already present in the multiple-value field.
$value_exists = FALSE;
foreach ($node->{$settings['field']} as $existing_value) {
if ($value == $existing_value[$storage_key]) {
$value_exists = TRUE;
continue;
}
}
if (!$value_exists) {
$node->{$settings['field']}[] = array(
$storage_key => $value,
);
}
}
// Return the node, so Rules can save it later on.
return array(
'node' => $node,
);
}