-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPatternLibraryJSONForm.php
More file actions
149 lines (133 loc) · 4.68 KB
/
PatternLibraryJSONForm.php
File metadata and controls
149 lines (133 loc) · 4.68 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Drupal\patternkit\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Settings form for configuring the JSON Library Plugin.
*/
class PatternLibraryJSONForm extends ConfigFormBase {
/**
* Settings identifier.
*
* @var string
*/
public const SETTINGS = 'patternkit.settings';
/**
* Array of themes supported by the JSON Schema Editor.
*
* @var array
*
* @see https://github.com/json-editor/json-editor
*
* @todo Move to yml config.
*
* @todo Materialize doesn't support the Shadow dom: figure out encapsulation.
*/
public const THEMES = [
'barebones' => [],
'html' => [],
'jqueryui' => [
'css' => 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css',
],
'bootstrap2' => [
'css' => 'https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css',
],
'bootstrap3' => [
'css' => 'https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
],
'bootstrap4' => [
'css' => 'library://patternkit/patternkit.jsoneditor.theme.bootstrap4/css',
],
'foundation3' => [
'css' => 'https://cdnjs.cloudflare.com/ajax/libs/foundation/3.2.5/stylesheets/foundation.css',
],
'foundation4' => [
'css' => 'https://cdnjs.cloudflare.com/ajax/libs/foundation/4.3.2/css/foundation.min.css',
],
'foundation5' => [
'css' => 'https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.3/css/foundation.min.css',
],
'foundation6' => [
'css' => 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.4/foundation.min.css',
],
];
/**
* Array of icons supported by the JSON Schema Editor.
*
* @var array
*
* @see https://github.com/json-editor/json-editor
*
* @todo Move to yml config.
*/
public const ICONS = [
'none' => '',
'jqueryui' => '',
'bootstrap2' => '',
'bootstrap3' => '',
'foundation2' => 'https://cdnjs.cloudflare.com/ajax/libs/foundicons/2.0/stylesheets/general_foundicons.css',
'foundation3' => 'https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css',
'fontawesome3' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.css',
'fontawesome4' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css',
'fontawesome5' => 'https://use.fontawesome.com/releases/v5.6.1/css/all.css',
];
/**
* Implements buildForm().
*
* {@inheritDoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) :array {
$config = $this->config(static::SETTINGS);
$themes = array_keys(static::THEMES);
$form['patternkit_json_editor_theme'] = array(
'#type' => 'select',
'#title' => t('Select the JSON Editor Theme'),
'#options' => array_combine($themes, $themes),
'#default_value' => $config->get('patternkit_json_editor_theme'),
);
$icons = array_keys(static::ICONS);
$form['patternkit_json_editor_icons'] = array(
'#type' => 'select',
'#title' => t('Select the icons to be used with the editor'),
'#options' => array_combine($icons, $icons),
'#default_value' => $config->get('patternkit_json_editor_icons'),
);
$form['patternkit_json_editor_css'] = array(
'#type' => 'textfield',
'#title' => t('Add to the editor theme CSS'),
'#description' => t('Enter a comma-separated list of additional CSS to include.'),
'#default_value' => $config->get('patternkit_json_editor_css'),
);
$form['patternkit_json_editor_js'] = array(
'#type' => 'textfield',
'#title' => t('Add to the editor theme JS'),
'#description' => t('Entter a comma-separated list of additional JS to include.'),
'#default_value' => $config->get('patternkit_json_editor_js'),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritDoc}
*/
protected function getEditableConfigNames() :array {
return [static::SETTINGS];
}
/**
* {@inheritDoc}
*/
public function getFormId() :string {
return 'patternkit_json_editor_config';
}
/**
* {@inheritDoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$this->config(static::SETTINGS)
->set('patternkit_json_editor_theme', $form_state->getValue('patternkit_json_editor_theme'))
->set('patternkit_json_editor_icons', $form_state->getValue('patternkit_json_editor_icons'))
->set('patternkit_json_editor_css', $form_state->getValue('patternkit_json_editor_css'))
->set('patternkit_json_editor_js', $form_state->getValue('patternkit_json_editor_js'))
->save();
parent::submitForm($form, $form_state);
}
}