1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Implements a generic entity delete action. Uses Entity API if available.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
function views_bulk_operations_delete_action_info() {
|
9 |
|
|
return array(
|
10 |
|
|
'views_bulk_operations_delete_item' => array(
|
11 |
|
|
'type' => 'entity',
|
12 |
|
|
'label' => t('Delete item'),
|
13 |
|
|
'configurable' => FALSE,
|
14 |
|
|
'behavior' => array('deletes_property'),
|
15 |
|
|
'triggers' => array('any'),
|
16 |
|
|
),
|
17 |
|
|
'views_bulk_operations_delete_revision' => array(
|
18 |
|
|
'type' => 'entity',
|
19 |
|
|
'label' => t('Delete revision'),
|
20 |
|
|
'configurable' => FALSE,
|
21 |
|
|
'behavior' => array('deletes_property'),
|
22 |
9df8b457
|
Assos Assos
|
'triggers' => array('any'),
|
23 |
85ad3d82
|
Assos Assos
|
),
|
24 |
|
|
);
|
25 |
|
|
}
|
26 |
|
|
|
27 |
7547bb19
|
Assos Assos
|
function views_bulk_operations_delete_item_views_bulk_operations_form($settings) {
|
28 |
|
|
$form = array();
|
29 |
|
|
$form['log'] = array(
|
30 |
|
|
'#type' => 'checkbox',
|
31 |
|
|
'#title' => t('Log individual deletions'),
|
32 |
|
|
'#description' => t('Note: Deleting large amounts of entities will generate large amounts of log messages.'),
|
33 |
|
|
'#default_value' => !empty($settings['log']),
|
34 |
|
|
);
|
35 |
|
|
|
36 |
|
|
return $form;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
85ad3d82
|
Assos Assos
|
function views_bulk_operations_delete_item($entity, $context) {
|
40 |
|
|
$info = entity_get_info($context['entity_type']);
|
41 |
|
|
$entity_id = $entity->{$info['entity keys']['id']};
|
42 |
|
|
|
43 |
|
|
entity_delete($context['entity_type'], $entity_id);
|
44 |
7547bb19
|
Assos Assos
|
|
45 |
|
|
// Add a message to the watchdog if we've been configured to do so.
|
46 |
|
|
if (!empty($context['settings']['log'])) {
|
47 |
|
|
// Log an appropriate message for this entity type, using the format from
|
48 |
|
|
// the node, taxonomy and user module for their entity types.
|
49 |
|
|
switch ($context['entity_type']) {
|
50 |
|
|
case 'node':
|
51 |
|
|
watchdog('content', '@type: deleted %title.', array('@type' => $entity->type, '%title' => $entity->title));
|
52 |
|
|
break;
|
53 |
|
|
|
54 |
|
|
case 'taxonomy_term':
|
55 |
|
|
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $entity->name), WATCHDOG_NOTICE);
|
56 |
|
|
break;
|
57 |
|
|
|
58 |
|
|
case 'user':
|
59 |
|
|
watchdog('user', 'Deleted user: %name %email.', array('%name' => $entity->name, '%email' => '<' . $entity->mail . '>'), WATCHDOG_NOTICE);
|
60 |
|
|
break;
|
61 |
|
|
|
62 |
|
|
default:
|
63 |
|
|
watchdog('entity', 'Deleted @type %label.', array('@type' => $context['entity_type'], '%label' => entity_label($context['entity_type'], $entity)));
|
64 |
|
|
break;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
85ad3d82
|
Assos Assos
|
}
|
68 |
|
|
|
69 |
|
|
function views_bulk_operations_delete_revision($entity, $context) {
|
70 |
|
|
$info = entity_get_info($context['entity_type']);
|
71 |
|
|
$revision_id = $entity->{$info['entity keys']['revision']};
|
72 |
|
|
entity_revision_delete($context['entity_type'], $revision_id);
|
73 |
|
|
} |