function ref_field_sync_remove_reference in (Entity)Reference Field Synchronization 7.2
Same name and namespace in other branches
- 7 ref_field_sync/ref_field_sync.module \ref_field_sync_remove_reference()
Remove a ref_field value form an entity
Parameters
string $type: The type of entity being modified
object $entity: The entity being modified
int $target_id: The ID of the entity who's reference should be removed
string $field_name: Name of the field to remove the reference from
2 calls to ref_field_sync_remove_reference()
- ref_field_sync_entity_delete in ./
ref_field_sync.module - Implements hook_entity_delete().
- ref_field_sync_entity_update in ./
ref_field_sync.module - Implements hook_entity_update().
File
- ./
ref_field_sync.module, line 358 - Hooks and main functions for ref_field module.
Code
function ref_field_sync_remove_reference($type, $entity, $target_id, $field_name) {
$lng = field_language($type, $entity, $field_name);
if ($items = field_get_items($type, $entity, $field_name)) {
foreach ($items as $key => $value) {
if ($value['target_id'] == $target_id) {
unset($entity->{$field_name}[$lng][$key]);
// Set flag to not process the calling entity again.
$entity->ref_field_caller = $target_id;
entity_save($type, $entity);
}
}
}
}