Skip to content

Commit bfdc357

Browse files
committed
Add local lib JSON Schema editor
feat(jsoneditor, PatternkitDrupalTwigLib) Adds a local JSON Schema editor from jdorn/json-editor and updates the necessary classes to support the functionality.
1 parent 7081996 commit bfdc357

File tree

10 files changed

+9241
-72
lines changed

10 files changed

+9241
-72
lines changed

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@
88
],
99
"require": {},
1010
"config": {},
11-
"repositories": []
11+
"repositories": [],
12+
"scripts": {
13+
"post-autoload-dump": [
14+
"wget -Oq -P js/ --no-check-certificate https://raw.github.com/jdorn/json-editor/master/dist/jsoneditor.min.js",
15+
"wget -Oq -P js/ --no-check-certificate https://raw.github.com/jdorn/json-editor/master/dist/jsoneditor.js"
16+
]
17+
}
1218
}

include/utility.inc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Utility functions for Patternkit.
6+
*/
7+
8+
/**
9+
* Utility function to get all Patternkit module metadata.
10+
*
11+
* @param string|null $subtype
12+
* If specified, return only the first metadata found for this subtype.
13+
* @param bool $reset
14+
* Optionally force the meta data to be reloaded.
15+
*
16+
* @return array|\PatternkitPattern
17+
* Array of metadata objects found or object if specific module requested.
18+
*
19+
* @todo Add support for multiple library implementation of a pattern.
20+
*/
21+
function _patternkit_get_metadata($subtype = NULL, $reset = FALSE) {
22+
$metadata = array();
23+
foreach (patternkit_pattern_libraries() as $lib) {
24+
if ($subtype === NULL) {
25+
$metadata += $lib->getCachedMetadata(NULL, $reset);
26+
continue;
27+
}
28+
$module = $lib->getCachedMetadata($subtype, $reset);
29+
if ($module !== NULL) {
30+
return $module;
31+
}
32+
}
33+
return $metadata;
34+
}
35+
36+
/**
37+
* Parses schema properties for $ref and updates their location.
38+
*
39+
* @param object $properties
40+
* The properties to parse.
41+
* @param array &$metadata
42+
* The library metadata to lookup referenced patterns in.
43+
*
44+
* @return object
45+
* The updated schema properties object.
46+
*/
47+
function _patternkit_schema_ref($properties, array &$metadata) {
48+
foreach ($properties as $property => $value) {
49+
if (!is_scalar($value)) {
50+
$new_value = _patternkit_schema_ref($value, $metadata);
51+
if (is_object($properties)) {
52+
$properties->{$property} = $new_value;
53+
}
54+
if (is_array($properties)) {
55+
$properties[$property] = $new_value;
56+
}
57+
continue;
58+
}
59+
if ($property !== '$ref') {
60+
continue;
61+
}
62+
$pattern = strstr($value, '.json', TRUE);
63+
$ref = substr($value, strlen("$pattern.json"));
64+
if (!isset($metadata[$pattern])) {
65+
unset($properties->{$property});
66+
continue;
67+
}
68+
$properties->{$property} = $metadata[$pattern]->url . $ref;
69+
}
70+
return $properties;
71+
}

0 commit comments

Comments
 (0)