-
Notifications
You must be signed in to change notification settings - Fork 19
/
jsonld.module
132 lines (127 loc) · 2.79 KB
/
jsonld.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
<?php
/**
* @file
* Adds support for serializing entities to JSON-LD / Islandora Project.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function jsonld_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.hal':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= t('<p><a href=":jsonld_spec">JSON-LD</a>, or JavaScript Object Notation for Linked Data, is
a method of encoding Linked Data using JSON.</p>', [':jsonld_spec' => 'http://json-ld.org/spec/latest/json-ld-syntax/']);
return $output;
}
}
/**
* Implements hook_rdf_namespaces().
*/
function jsonld_rdf_namespaces() {
$config = \Drupal::config('jsonld.settings');
$namespace_config = $config->get('rdf_namespaces');
if (!is_array($namespace_config)) {
// No namespaces have been configured, return empty.
return [];
}
$namespaces = [];
foreach ($namespace_config as $namespace) {
$namespaces[$namespace['prefix']] = $namespace['namespace'];
}
return $namespaces;
}
/**
* Implements hook_jsonld_field_mappings().
*/
function jsonld_jsonld_field_mappings() {
return [
"comment" => [
"@type" => "xsd:string",
],
"datetime" => [
"@type" => "xsd:dateTime",
],
"file" => [
"@type" => "@id",
],
"image" => [
"@type" => "@id",
],
"link" => [
"@type" => "xsd:anyURI",
],
"list_float" => [
"@type" => "xsd:float",
"@container" => "@list",
],
"list_integer" => [
"@type" => "xsd:int",
"@container" => "@list",
],
"list_string" => [
"@type" => "xsd:string",
"@container" => "@list",
],
"path" => [
"@type" => "xsd:anyURI",
],
"text" => [
"@type" => "xsd:string",
],
"text_with_summary" => [
"@type" => "xsd:string",
],
"text_long" => [
"@type" => "xsd:string",
],
"uuid" => [
"@type" => "xsd:string",
],
"uri" => [
"@type" => "xsd:anyURI",
],
"language" => [
"@type" => "xsd:language",
],
"string_long" => [
"@type" => "xsd:string",
],
"changed" => [
"@type" => "xsd:dateTime",
],
"map" => "xsd:",
"boolean" => [
"@type" => "xsd:boolean",
],
"email" => [
"@type" => "xsd:string",
],
"integer" => [
"@type" => "xsd:int",
],
"decimal" => [
"@type" => "xsd:decimal",
],
"created" => [
"@type" => "xsd:dateTime",
],
"float" => [
"@type" => "xsd:float",
],
"entity_reference" => [
"@type" => "@id",
],
"timestamp" => [
"@type" => "xsd:dateTime",
],
"string" => [
"@type" => "xsd:string",
],
"password" => [
"@type" => "xsd:string",
],
];
}