applyEditorPreferences(); $this->fillFromConfig([ 'language', 'showGutter', 'wordWrap', 'codeFolding', 'autoClosing', 'useSoftTabs', 'tabSize', 'fontSize', 'margin', 'theme', ]); } /** * {@inheritDoc} */ public function render() { $this->prepareVars(); return $this->makePartial('codeeditor'); } /** * Prepares the widget data */ public function prepareVars() { $this->vars['fontSize'] = $this->fontSize; $this->vars['wordWrap'] = $this->wordWrap; $this->vars['codeFolding'] = $this->codeFolding; $this->vars['autoClosing'] = $this->autoClosing; $this->vars['tabSize'] = $this->tabSize; $this->vars['theme'] = $this->theme; $this->vars['showInvisibles'] = $this->showInvisibles; $this->vars['highlightActiveLine'] = $this->highlightActiveLine; $this->vars['useSoftTabs'] = $this->useSoftTabs; $this->vars['showGutter'] = $this->showGutter; $this->vars['language'] = $this->language; $this->vars['margin'] = $this->margin; $this->vars['stretch'] = $this->formField->stretch; $this->vars['size'] = $this->formField->size; $this->vars['name'] = $this->formField->getName(); // Double encode when escaping $this->vars['value'] = htmlentities($this->getLoadValue(), ENT_QUOTES, 'UTF-8', true); } /** * {@inheritDoc} */ public function loadAssets() { $this->addCss('css/codeeditor.css', 'core'); $this->addJs('vendor/emmet/emmet.js', 'core'); $this->addJs('vendor/ace/ace.js', 'core'); $this->addJs('vendor/ace/ext-emmet.js', 'core'); $this->addJs('js/codeeditor.js', 'core'); } /** * Looks at the user preferences and overrides any set values. * @return void */ protected function applyEditorPreferences() { // Load the editor system settings $editorSettings = EditorPreferences::instance(); $this->fontSize = $editorSettings->font_size; $this->wordWrap = $editorSettings->word_wrap; $this->codeFolding = $editorSettings->code_folding; $this->autoClosing = $editorSettings->auto_closing; $this->tabSize = $editorSettings->tab_size; $this->theme = $editorSettings->theme; $this->showInvisibles = $editorSettings->show_invisibles; $this->highlightActiveLine = $editorSettings->highlight_active_line; $this->useSoftTabs = !$editorSettings->use_hard_tabs; $this->showGutter = $editorSettings->show_gutter; } }