Skip to content

Commit 14372bc

Browse files
committed
Updates editor and caching config defaults
fix(jsoneditor, LibraryLoader, LibraryCollector)
1 parent 5820c7b commit 14372bc

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

js/patternkit.jsoneditor.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@
4646
var data = {};
4747
data.schema = JSON.parse(drupalSettings.patternkitEditor.schemaJson);
4848
data.starting = JSON.parse(drupalSettings.patternkitEditor.startingJson);
49-
data.icons = drupalSettings.patternkitEditor.icons;
5049

51-
if (data.starting !== null) {
52-
JSONEditor.defaults.options.startval = data.starting;
53-
}
5450
JSONEditor.defaults.options.theme = drupalSettings.patternkitEditor.theme;
5551
JSONEditor.defaults.options.iconlib = drupalSettings.patternkitEditor.icons;
5652
JSONEditor.defaults.options.keep_oneof_values = false;
@@ -122,12 +118,14 @@
122118
};
123119

124120
// Initialize the editor with a JSON schema.
125-
var editor = new JSONEditor(
126-
$target[0].shadowRoot.getElementById('editor_holder'), {
127-
schema: data.schema,
128-
refs: { }
129-
}
130-
);
121+
var config = {
122+
schema: data.schema,
123+
refs: { }
124+
};
125+
if (typeof data.starting === 'object' && !$.isEmptyObject(data.starting)) {
126+
config.startval = data.starting;
127+
}
128+
var editor = new JSONEditor($target[0].shadowRoot.getElementById('editor_holder'), config);
131129
JSONEditor.plugins.sceditor.emoticonsEnabled = false;
132130
var saveSchema = function () {
133131
$('#schema_instance_config').val(JSON.stringify(editor.getValue()));
@@ -150,7 +148,6 @@
150148
// to trigger the editor update with latest field values.
151149
// @TODO Add handling for AJAX errors and re-attach.
152150
Drupal.Ajax.prototype.beforeSubmit = function(formValues, element, options) {
153-
debugger;
154151
editor.disable();
155152
saveSchema();
156153
for (var v = 0; v < formValues.length; v++) {

src/Loader/PatternLibraryLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Drupal\Core\Logger\LoggerChannelInterface;
66
use Drupal\patternkit\PatternLibraryCollector;
7-
use Exception;
87

98
/**
109
* Functionality for parsing Twig pattern libraries.
@@ -31,7 +30,7 @@ public function __construct($paths,
3130
try {
3231
$libraries = $pattern_collector->getLibraryDefinitions();
3332
}
34-
catch (Exception $exception) {
33+
catch (\Exception $exception) {
3534
$logger->error('Error loading pattern libraries: @message', ['@message' => $exception->getMessage()]);
3635
}
3736
foreach ($libraries as $namespace => $library) {

src/PatternLibraryCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function getLibraryDefinitions(): array {
157157
$cached_metadata = $this->getLibraryMetadata();
158158
// Cache the data so that we don't have to build it again.
159159
// (if cache enabled, otherwise just a slow, redundant memcache set).
160-
if ($cache_enabled === TRUE) {
160+
if ($cache_enabled) {
161161
// Explicit copy of the data into cache_set to avoid implicit copy.
162162
$this->cache->set(static::PERSISTENT_CACHE_ID,
163163
$cached_metadata);

0 commit comments

Comments
 (0)