forked from btmash/islandora_entity_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_entity_bridge.module
373 lines (334 loc) · 11.3 KB
/
islandora_entity_bridge.module
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
/**
* @file
* Module file for the Islandora Entity Bridge module.
*/
/**
* Implements hook_action_info().
*/
function islandora_entity_bridge_action_info() {
$actions = array();
$actions['islandora_entity_bridge_object_active_action'] = array(
'type' => 'islandora_entity_bridge',
'label' => t('Publish islandora entity bridge object'),
'configurable' => FALSE,
);
$actions['islandora_entity_bridge_object_inactive_action'] = array(
'type' => 'islandora_entity_bridge',
'label' => t('Unpublish islandora entity bridge object'),
'configurable' => FALSE,
);
return $actions;
}
/**
* Implements hook_entity_info().
*/
function islandora_entity_bridge_entity_info() {
$entities = array();
$entities['islandora_entity_bridge'] = array(
'label' => t('Islandora Entity Bridge Object'),
'label callback' => 'islandora_entity_bridge_label',
'entity class' => 'IslandoraEntityBridge',
'controller class' => 'IslandoraEntityBridgeController',
'base table' => 'islandora_entity_bridge_mapping',
'uri callback' => 'islandora_entity_bridge_uri',
'static cache' => FALSE,
'field cache' => FALSE,
'entity cache' => FALSE,
'load hook' => 'islandora_entity_bridge_load',
'fieldable' => TRUE,
'module' => 'islandora_entity_bridge',
'access callback' => 'islandora_entity_bridge_access_callback',
'entity keys' => array(
'id' => 'iebid',
'label' => 'label',
'bundle' => 'type',
),
'bundles' => array(),
'view modes' => array(
'full' => array(
'label' => t('Full content'),
'custom settings' => FALSE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom settings' => TRUE,
),
'preview' => array(
'label' => t('Preview'),
'custom settings' => FALSE,
),
),
);
foreach (_islandora_entity_bridge_get_content_models() as $pid => $content_model) {
$entities['islandora_entity_bridge']['bundles'][$pid] = array(
'label' => $content_model['label'],
'admin' => array(
'path' => 'admin/structure/ieb_cmodel/manage/%islandora_entity_bridge_cmodel',
'real path' => 'admin/structure/ieb_cmodel/manage/' . $pid,
'bundle argument' => 4,
'access arguments' => array('administer content types'),
),
);
}
return $entities;
}
/**
* Implements hook_menu().
*/
function islandora_entity_bridge_menu() {
$items = array();
$items['islandora_entity_bridge/%islandora_entity_bridge'] = array(
'title' => 'Islandora Entity Bridge Object',
'page callback' => 'islandora_entity_bridge_view_entity',
'page arguments' => array(1),
'access callback' => 'islandora_entity_bridge_access_menu_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 1),
);
$items['admin/structure/ieb_cmodel'] = array(
'title' => 'Islandora Entity Bridge',
'description' => 'Manage fields and mostly display for the various CModels',
'page callback' => 'islandora_entity_bridge_overview_cmodels',
'access arguments' => array(ISLANDORA_ADD_DS),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/islandora_entity_bridge.cmodel.inc',
);
$items['admin/structure/ieb_cmodel/manage'] = array(
'title' => 'List',
'type' => MENU_CALLBACK,
);
return $items;
}
/*
* Implements hook_entity_property_info().
*/
function islandora_entity_bridge_entity_property_info() {
$info = array();
// Add meta-data about the basic node properties.
$properties = &$info['islandora_entity_bridge']['properties'];
$properties['iebid'] = array(
'label' => t("Islandora Entity Bridge ID"),
'type' => 'integer',
'description' => t("The Drupal-side ID of the Islandora/Fedora Object."),
'schema field' => 'iebid',
);
$properties['pid'] = array(
'label' => t("PID"),
'description' => t("The Islandora/Fedora object ID."),
'setter callback' => 'entity_property_verbatim_set',
'schema field' => 'pid',
'required' => TRUE,
);
$properties['type'] = array(
'label' => t("Type"),
'description' => t("The Islandora/Fedora object CModel."),
'setter callback' => 'entity_property_verbatim_set',
'schema field' => 'type',
'required' => TRUE,
);
$properties['label'] = array(
'label' => t("Label"),
'description' => t("The Islandora/Fedora object Title/Label."),
'setter callback' => 'entity_property_verbatim_set',
'schema field' => 'label',
'required' => TRUE,
);
$properties['state'] = array(
'label' => t("Status"),
'description' => t("The Islandora/Fedora object status (Active, Inactive, Deleted)."),
'setter callback' => 'entity_property_verbatim_set',
'schema field' => 'state',
'required' => TRUE,
);
return $info;
}
/**
* Implements hook_islandora_object_ingested().
*/
function islandora_entity_bridge_islandora_object_ingested(AbstractObject $object) {
$values = array(
'pid' => $object->id,
'type' => $object->models[0],
'label' => $object->label,
'state' => $object->state,
);
$islandora_entity_bridge_object = entity_create('islandora_entity_bridge', $values);
$islandora_entity_bridge_object->save();
}
/**
* Implements hook_islandora_object_modified().
*/
function islandora_entity_bridge_islandora_object_modified(AbstractObject $object) {
$results = db_select('islandora_entity_bridge_mapping', 'iebm')
->fields('iebm', array('iebid'))
->condition('iebm.pid', $object->id)
->execute();
if ($results->rowCount() > 0) {
foreach ($results as $result) {
$islandora_entity_bridge_object = islandora_entity_bridge_load($result->iebid);
$islandora_entity_bridge_object->pid = $object->id;
$islandora_entity_bridge_object->type = $object->models[0];
$islandora_entity_bridge_object->label = $object->label;
$islandora_entity_bridge_object->state = $object->state;
$islandora_entity_bridge_object->save();
}
}
else {
islandora_entity_bridge_islandora_object_ingested($object);
}
}
/**
* Implements hook_islandora_datastream_modified().
*/
function islandora_entity_bridge_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) {
islandora_entity_bridge_islandora_object_modified($object);
}
/**
* Implements islandora_view_object().
*/
function islandora_entity_bridge_islandora_view_object(AbstractObject $object) {
$results = db_select('islandora_entity_bridge_mapping', 'iebm')
->fields('iebm', array('iebid'))
->condition('iebm.pid', $object->id)
->execute();
if ($results->rowCount() > 0) {
// Do nothing.
}
else {
islandora_entity_bridge_islandora_object_ingested($object);
}
}
/**
* Implements hook_islandora_object_purged().
*/
function islandora_entity_bridge_islandora_object_purged($object) {
$id = $object;
if (is_object($object)) {
$id = $object->id;
}
$results = db_select('islandora_entity_bridge_mapping', 'iebm')
->fields('iebm', array('iebid'))
->condition('iebm.pid', $id)
->execute();
if ($results->rowCount() > 0) {
foreach ($results as $result) {
$islandora_entity_bridge_object = islandora_entity_bridge_load($result->iebid);
$islandora_entity_bridge_object->delete();
}
}
}
/**
* Implements hook_views_api().
*/
function islandora_entity_bridge_views_api() {
return array(
'api' => '3',
);
}
/**
* Check access permission for Islandora Entity Bridge Entity UI.
*/
function islandora_entity_bridge_access_menu_callback($op, $islandora_entity_bridge_object = NULL, $account = NULL) {
$islandora_object = islandora_object_load($islandora_entity_bridge_object->pid);
return islandora_object_access_callback($op, $islandora_object);
}
/**
* Access callback for Islandora Entity Bridge Objects.
*/
function islandora_entity_bridge_access_callback() {
return user_access(ISLANDORA_VIEW_OBJECTS);
}
/**
* Autoloader callback for entity cmodel.
*/
function islandora_entity_bridge_cmodel_load($islandora_entity_bridge_cmodel) {
$content_model = _islandora_entity_bridge_get_content_models($islandora_entity_bridge_cmodel);
if (!empty($content_model)) {
return $content_model['pid'];
}
return NULL;
}
/**
* Autoloader callback for entity object.
*/
function islandora_entity_bridge_load($islandora_entity_bridge_object_id, $reset = FALSE) {
$islandora_entity_bridge_objects = islandora_entity_bridge_load_multiple(array($islandora_entity_bridge_object_id), array(), $reset);
return reset($islandora_entity_bridge_objects);
}
/**
* Loads multiple entity objects.
*/
function islandora_entity_bridge_load_multiple($islandora_entity_bridge_object_ids = array(), $conditions = array('in_office' => 1), $reset = FALSE) {
return entity_load('islandora_entity_bridge', $islandora_entity_bridge_object_ids, $conditions, $reset);
}
/**
* Deletes an islandora entity bridge object.
*/
function islandora_entity_bridge_delete(IslandoraEntityBridge $islandora_entity_bridge_object) {
$islandora_entity_bridge_object->delete();
}
/**
* Delete multiple islandora entity bridge objects.
*/
function islandora_entity_bridge_delete_multiple(array $islandora_entity_bridge_object_ids) {
entity_get_controller('islandora_entity_bridge')->delete($islandora_entity_bridge_object_ids);
}
/**
* Label callback for islandora entity bridge objects, for menu router, etc.
*/
function islandora_entity_bridge_label($islandora_entity_bridge_object, $type) {
if (!isset($islandora_entity_bridge_object->label)) {
return '';
}
$label = $islandora_entity_bridge_object->label;
$context = clone $islandora_entity_bridge_object;
drupal_alter('islandora_entity_bridge_object_label', $label, $context);
return $label;
}
/**
* URI callback for islandora entity bridge objects.
*/
function islandora_entity_bridge_uri($islandora_entity_bridge_object) {
return array('path' => 'islandora/object/' . $islandora_entity_bridge_object->pid);
}
/**
* View for /islandora_entity_bridge/<$islandora_entity_bridge_object_id> page.
*/
function islandora_entity_bridge_view_entity($islandora_entity_bridge_object) {
drupal_set_title($islandora_entity_bridge_object->label);
return entity_view('islandora_entity_bridge', array($islandora_entity_bridge_object), 'full');
}
/**
* Publishes / sets Islandora Objects to 'Active'.
*/
function islandora_entity_bridge_object_active_action($islandora_entity_bridge_object, $context) {
$islandora_object = islandora_object_load($islandora_entity_bridge_object->pid);
$islandora_object->state = 'A';
}
/**
* Publishes / sets Islandora Objects to 'Inactive'.
*/
function islandora_entity_bridge_object_inactive_action($islandora_entity_bridge_object, $context) {
$islandora_object = islandora_object_load($islandora_entity_bridge_object->pid);
$islandora_object->state = 'I';
}
/**
* Retrieves list of Content Models.
*/
function _islandora_entity_bridge_get_content_models($content_model = NULL) {
module_load_include('inc', 'islandora', 'includes/utilities');
static $content_models;
if (!isset($content_models)) {
$content_models = array();
foreach (islandora_get_content_models(TRUE) as $cmodel) {
$content_models[$cmodel['pid']] = $cmodel;
}
}
if (!empty($content_model) && isset($content_models[$content_model])) {
return $content_models[$content_model];
}
elseif (isset($content_model)) {
return FALSE;
}
return $content_models;
}