function node_gallery_api_rules_item_add in Node Gallery 7
Rules action for adding a gallery item to a gallery.
Parameters
object $item_wrapper: Gallery Item
object $gallery_wrapper: Gallery
1 string reference to 'node_gallery_api_rules_item_add'
- node_gallery_api_rules_action_info in ./
node_gallery_api.rules.inc - Implements hook_rules_action_info().
File
- ./
node_gallery_api.rules.inc, line 149 - Rules module integration.
Code
function node_gallery_api_rules_item_add($item_wrapper, $gallery_wrapper) {
$relationship_type = node_gallery_api_get_relationship_type($gallery_wrapper->type
->value(), $item_wrapper->type
->value());
if (!empty($relationship_type)) {
$field_name = node_gallery_api_get_item_field_name(NULL, NULL, $relationship_type->id);
$galleries = $item_wrapper->{$field_name}
->value();
if (!is_array($galleries)) {
// If cardinality == 1, entity wrapper gives us an object.
// In this case, replace existing gallery.
$galleries = $gallery_wrapper
->value();
}
else {
$galleries[] = $gallery_wrapper
->value();
}
$item_wrapper->{$field_name}
->set($galleries);
}
}