function message_entity_delete in Message 7
Same name and namespace in other branches
- 8 message.module \message_entity_delete()
Implements hook_entity_delete().
Handles messages deletion when referenced entities are being deleted.
Parameters
$entity: The entity object.
$entity_type: The type of entity being deleted (i.e. node, user, comment).
1 string reference to 'message_entity_delete'
- message_entity_delete_queue_worker in ./
message.module - Queue API worker; Process a queue item.
File
- ./
message.module, line 381 - API functions to manipulate messages.
Code
function message_entity_delete($entity, $entity_type) {
if ($entity_type == 'message') {
return;
}
if (!($field_names = _message_get_referenced_fields($entity_type, $entity))) {
return;
}
list($entity_id) = entity_extract_ids($entity_type, $entity);
// A deleted message with no reference doesn't need to create a queue worker.
$delete_referenced_entities = FALSE;
foreach ($field_names as $field_name) {
$field = field_info_field($field_name);
$columns = array_keys($field['columns']);
// Fetch messages with fields referencing the deleted entity.
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'message')
->fieldCondition($field['field_name'], $columns[0], $entity_id)
->execute();
if (!empty($result['message'])) {
$delete_referenced_entities = TRUE;
break;
}
}
if (!$delete_referenced_entities) {
return;
}
if (variable_get('message_use_queue')) {
$data = array(
'range' => 200,
'last_mid' => 0,
'field_names' => $field_names,
'entity_id' => $entity_id,
);
$queue = DrupalQueue::get('message_entity_delete');
return $queue
->createItem($data);
}
_message_delete_messages($field_names, $entity_id);
}