Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/install/yaml_editor.config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
editor_source: //cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/ace.min.js
editor_theme: ace/theme/chrome
10 changes: 10 additions & 0 deletions config/schema/yaml_editor.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
yaml_editor.config:
type: config_object
label: 'Yaml Editor Config'
mapping:
editor_source:
type: string
label: 'Editor source'
editor_theme:
type: string
label: 'Editor theme'
2 changes: 1 addition & 1 deletion js/yaml-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
editor.getSession().setValue($textarea.val());
editor.getSession().setMode('ace/mode/yaml');
editor.getSession().setTabSize(2);
editor.setTheme('ace/theme/chrome');
editor.setTheme(drupalSettings.yamlEditor.theme);
editor.setOptions({
minLines: 3,
maxLines: 20
Expand Down
9 changes: 9 additions & 0 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $config->get('editor_source'),
];

$form['editor_theme'] = [
'#type' => 'textfield',
'#title' => $this->t('Editor theme'),
'#description' => $this->t('Enter name of Ace theme to use.'),
'#default_value' => $config->get('editor_theme'),
];

return parent::buildForm($form, $form_state);
}

Expand All @@ -61,9 +68,11 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$editor_source = $form_state->getValue('editor_source');
$editor_theme = $form_state->getValue('editor_theme');

$this->config('yaml_editor.config')
->set('editor_source', $editor_source)
->set('editor_theme', $editor_theme)
->save();

parent::submitForm($form, $form_state);
Expand Down
11 changes: 11 additions & 0 deletions yaml_editor.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* Set default editor_theme in config.
*/
function yaml_editor_update_8001() {
\Drupal::configFactory()
->getEditable('yaml_editor.config')
->set('editor_theme', 'ace/theme/chrome')
->save(TRUE);
}
5 changes: 4 additions & 1 deletion yaml_editor.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ function yaml_editor_page_attachments(array &$attachments) {
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);

if ($is_admin) {
$source = \Drupal::config('yaml_editor.config')->get('editor_source');
$config = \Drupal::config('yaml_editor.config');
$source = $config->get('editor_source');
$theme = $config->get('editor_theme');

$attachments['#attached']['drupalSettings']['yamlEditor']['source'] = $source;
$attachments['#attached']['drupalSettings']['yamlEditor']['theme'] = $theme;
$attachments['#attached']['library'][] = 'yaml_editor/yaml_editor';
}
}