You are here

public function NodeGalleryBehaviorHandler::galleriesGetDiff in Node Gallery 7

Get the difference in group audience for a saved field.

Return value

array Array with all the differences, or an empty array if none found.

1 call to NodeGalleryBehaviorHandler::galleriesGetDiff()
NodeGalleryBehaviorHandler::NodeGalleryRelationshipCrud in plugins/entityreference/behavior/NodeGalleryBehaviorHandler.class.php
Create, update or delete Node Gallery relationships based on field values.

File

plugins/entityreference/behavior/NodeGalleryBehaviorHandler.class.php, line 101
Node Gallery EntityReference behavior plugin.

Class

NodeGalleryBehaviorHandler
Node Gallery behavior handler.

Code

public function galleriesGetDiff($entity_type, $entity, $field, $instance, $langcode, $items) {
  $return = FALSE;
  $current_relationships = node_gallery_api_get_relationships(NULL, $entity->nid);
  $new_relationships = array();
  foreach ($items as $item) {
    $new_relationships[$item['target_id']] = TRUE;
  }
  foreach ($current_relationships as $current_relationship) {
    $ngid = $current_relationship->ngid;
    if (empty($new_relationships[$ngid])) {

      // Relationship was deleted.
      $return['delete'][$current_relationship->id] = $current_relationship->ngid;
      unset($new_relationships[$ngid]);
    }
    else {

      // Existing membership.
      unset($new_relationships[$ngid]);
    }
  }
  if ($new_relationships) {

    // New memberships.
    $return['insert'] = array_keys($new_relationships);
  }
  return $return;
}