function node_gallery_api_rules_item_remove in Node Gallery 7
Rules action for removing a gallery item from a gallery.
Parameters
object $item_wrapper: Gallery Item
object $gallery_wrapper: Gallery
1 string reference to 'node_gallery_api_rules_item_remove'
- node_gallery_api_rules_action_info in ./
node_gallery_api.rules.inc - Implements hook_rules_action_info().
File
- ./
node_gallery_api.rules.inc, line 174 - Rules module integration.
Code
function node_gallery_api_rules_item_remove($item_wrapper, $gallery_wrapper) {
$relationships = node_gallery_api_get_relationships($gallery_wrapper->nid
->value(), $item_wrapper->nid
->value());
if (!empty($relationships)) {
foreach ($relationships as $relationship) {
$field_name = node_gallery_api_get_item_field_name(NULL, NULL, $relationship->relationship_type);
$galleries = $item_wrapper->{$field_name}
->value();
if (!is_array($galleries)) {
// If cardinality == 1, entity wrapper gives us an object.
if ($galleries->nid == $gallery_wrapper->nid
->value()) {
$item_wrapper->{$field_name}
->set(NULL);
}
}
else {
foreach ($galleries as $i => $g) {
if ($g->nid == $gallery_wrapper->nid
->value()) {
$item_wrapper->{$field_name}
->offsetUnset($i);
}
}
}
}
}
}