forked from Islandora/islandora_solution_pack_collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.form.inc
91 lines (85 loc) · 2.98 KB
/
migrate.form.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* @file
* Shares an object that is not a collection to an additional collection.
*/
/**
* Form setup.
*
* @param array $form
* Form variable
* @param array $form_state
* The context of this form.
* @param object $islandora_object
* The object to perform the operation on
*/
function islandora_basic_collection_migrate_item_form($form, &$form_state, $islandora_object) {
$form['description'] = array(
'#type' => 'item',
'#title' => t('Migrate this item'),
);
$form['new_collection_name'] = array(
'#autocomplete_path' => 'islandora/basic_collection/find_collections',
'#type' => 'textfield',
'#title' => t('New Collection'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Migrate Object',
);
$form_state['basic_collection_migrate'] = $islandora_object->id;
return $form;
}
/**
* Validates the form.
*
* @param array $form
* Form variable
* @param array $form_state
* The context of this form.
*/
function islandora_basic_collection_migrate_item_form_validate($form, &$form_state) {
$new_collection = islandora_object_load($form_state['values']['new_collection_name']);
$collection_models = islandora_basic_collection_get_collection_content_models();
if ($form_state['values']['new_collection_name'] == $form_state['basic_collection_migrate']) {
form_set_error('new_collection_name', t('Collections may not be children of themselves.'));
}
$is_a_collection = FALSE;
if (is_object($new_collection)) {
$is_a_collection = (
(count(array_intersect($collection_models, $new_collection->models)) > 0) &&
isset($new_collection['COLLECTION_POLICY'])
);
}
if (!$is_a_collection) {
form_set_error('new_collection_name', t('Not a valid collection'));
}
$has_ingest_permissions = islandora_object_access(ISLANDORA_INGEST, $new_collection);
if (!$has_ingest_permissions) {
form_set_error('new_collection_name', t('You do not have permission to ingest objects to this collection'));
}
}
/**
* Processes the form and migrates the objects.
*
* @param array $form
* Form variable
* @param array $form_state
* The context of this form.
*/
function islandora_basic_collection_migrate_item_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora_basic_collection', 'includes/utilities');
$object = islandora_object_load($form_state['basic_collection_migrate']);
$new_collection = islandora_object_load($form_state['values']['new_collection_name']);
$current_parents = islandora_basic_collection_get_parent_pids($object);
if ($object && $new_collection) {
foreach ($current_parents as $parent) {
islandora_basic_collection_remove_from_collection($object, $parent);
}
islandora_basic_collection_add_to_collection($object, $new_collection);
$message = t('The object @object has been added to @collection', array(
'@object' => $object->label,
'@collection' => $new_collection->label));
drupal_set_message($message);
}
}