-
Notifications
You must be signed in to change notification settings - Fork 2
/
wwudora.module
95 lines (83 loc) · 2.7 KB
/
wwudora.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
<?php
/**
* @file
* Customizations for WWU.
*/
/**
* Implements hook_islandora_oai_get_xsl_files().
*/
function wwudora_islandora_oai_get_xsl_files() {
$module_path = drupal_get_path('module', 'wwudora');
return array(
"$module_path/xml/wwu_mods_to_dc.xsl" => 'wwu_mods_to_dc.xsl',
);
}
/**
* Implements hook_xml_form_builder_get_transforms().
*/
function wwudora_xml_form_builder_get_transforms() {
$module_path = drupal_get_path('module', 'wwudora');
return array(
'wwu_mods_to_dc.xsl' => "$module_path/xml/wwu_mods_to_dc.xsl",
);
}
/**
* Implements hook_islandora_compound_object_children_added_to_parent().
*/
function wwudora_islandora_compound_object_children_added_to_parent($children, $parent_pids) {
/* We're only taking the first entry in the $parent_pids because:
* 1. Client expects children to only exist on one Compound Object
* 2. Each Policy would be overwritten by subsequent parents
*/
module_load_include('inc', 'wwudora', 'includes/derivatives');
$parent = islandora_object_load(current($parent_pids));
foreach ($children as $child) {
wwudora_inherit_xacml_from_compound_parent($parent, $child);
}
}
/**
* Implements hook_CMODEL_PID_islandora_derivative().
*/
function wwudora_islandora_compoundcmodel_islandora_derivative($object, $ds_modified_params = array()) {
$derivatives[] = array(
'source_dsid' => 'POLICY',
'weight' => '0',
'function' => array(
'wwudora_policy_to_children_derivatives',
),
'file' => drupal_get_path('module', 'wwudora') . '/includes/derivatives.inc',
);
return $derivatives;
}
/**
* Implements hook_islandora_datastream_ingested().
*/
function wwudora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
_wwudora_transform_mods_to_dc($datastream);
}
/**
* Implements hook_islandora_datastream_modified().
*/
function wwudora_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream, array $params) {
_wwudora_transform_mods_to_dc($datastream);
}
/**
* Helper function to transform mods to dc records.
*/
function _wwudora_transform_mods_to_dc(AbstractDatastream $datastream) {
if ($datastream->id == "MODS") {
$module_path = drupal_get_path('module', 'wwudora');
$transform_path = "$module_path/xml/wwu_mods_to_dc.xsl";
$transform = new DOMDocument();
$transform->load($transform_path);
$xslt = new XSLTProcessor();
$xslt->importStyleSheet($transform);
$mods = new DOMDocument();
$mods->loadXML($datastream->content);
$dc = $xslt->transformToDoc($mods);
if ($dc && isset($dc->documentElement)) {
$object = $datastream->parent;
$object["DC"]->setContentFromString($dc->saveXML());
}
}
}