forked from mjordan/islandora_premis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_premis.api.php
46 lines (41 loc) · 1.15 KB
/
islandora_premis.api.php
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
<?php
/**
* @file
* Hooks for the Islandora PREMIS Integration module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the serialized Turtle.
*
* Implementations should use EasyRdf or another Turtle library
* instead of manually altering the Turtle.
*
* @param string $nid
* The current node's ID.
* @param string $turtle
* The serialized Turtle.
*/
function hook_islandora_premis_turtle_alter($nid, &$turtle) {
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', ltrim($current_path, '/'));
if (count($path_args) == 3 && $path_args[0] == 'node' && $path_args[2] == 'premis') {
$nid = $path_args[1];
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
}
if (!$node) {
return array();
}
$base_url = \Drupal::request()->getSchemeAndHttpHost();
$resource = $base_url . '/node/' . $nid;
$url = $base_url . '/node/' . $nid . "?_format=jsonld";
$graph = EasyRdf_Graph::newAndLoad($url);
$graph->addType($resource, "http://www.loc.gov/premis/rdf/v3/IntellectualEntity");
$data = $graph->serialise('turtle');
$turtle .= $data;
}
/**
* @} End of "addtogroup hooks".
*/