Commit bc0c8eb3 authored by git's avatar git Committed by Ra Mänd
Browse files

Issue #2872350 by Joel James, sarvab, Ronino: Hook for field collections archive

parent dc32e2ee
...@@ -113,6 +113,22 @@ function hook_field_collection_item_delete(FieldCollectionItemEntity $field_coll ...@@ -113,6 +113,22 @@ function hook_field_collection_item_delete(FieldCollectionItemEntity $field_coll
->execute(); ->execute();
} }
/**
* Responds to field collection item archiving.
*
* This hook is invoked after the field collection item has been archived while
* removing it from its host entity.
*
* @param FieldCollectionItemEntity $field_collection_item
* The field collection item that is being archived.
*/
function hook_field_collection_item_archive(FieldCollectionItemEntity $field_collection_item) {
db_update('mytable')
->fields(array('archived' => 1))
->condition('id', entity_id('field_collection_item', $field_collection_item))
->execute();
}
/** /**
* Act on a field collection item that is being assembled before rendering. * Act on a field collection item that is being assembled before rendering.
* *
......
...@@ -607,6 +607,10 @@ class FieldCollectionItemEntity extends Entity { ...@@ -607,6 +607,10 @@ class FieldCollectionItemEntity extends Entity {
->fields(array('archived' => 1, 'revision_id' => $row['revision_id'])) ->fields(array('archived' => 1, 'revision_id' => $row['revision_id']))
->condition('item_id', $this->item_id) ->condition('item_id', $this->item_id)
->execute(); ->execute();
// Let other modules know about the archived item.
entity_get_controller('field_collection_item')->invoke('archive', $this);
entity_get_controller('field_collection_item')->resetCache(array($this->item_id)); entity_get_controller('field_collection_item')->resetCache(array($this->item_id));
entity_revision_delete('field_collection_item', $this->revision_id); entity_revision_delete('field_collection_item', $this->revision_id);
} }
......
...@@ -631,6 +631,13 @@ function field_collection_field_update($host_entity_type, $host_entity, $field, ...@@ -631,6 +631,13 @@ function field_collection_field_update($host_entity_type, $host_entity, $field,
->fields(array('archived' => 1)) ->fields(array('archived' => 1))
->condition('item_id', $ids, 'IN') ->condition('item_id', $ids, 'IN')
->execute(); ->execute();
// Let other modules know about the archived items.
foreach (field_collection_item_load_multiple($ids) as $un_item) {
entity_get_controller('field_collection_item')->invoke('archive', $un_item);
entity_get_controller('field_collection_item')->resetCache(array($un_item->item_id));
}
} }
else { else {
// Load items from the original entity from all languages checking which // Load items from the original entity from all languages checking which
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment