From 64ac4a614f13383d415392994706ca4c0edec579 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 3 May 2019 21:51:17 -0700 Subject: [PATCH] afform_html - Statically load Monaco editor --- .../html/CRM/AfformHtml/Page/HtmlEditor.php | 17 ++++++++--- .../CRM/AfformHtml/Page/HtmlEditor.tpl | 30 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/ext/afform/html/CRM/AfformHtml/Page/HtmlEditor.php b/ext/afform/html/CRM/AfformHtml/Page/HtmlEditor.php index d2bd59303f..89d4767ea9 100644 --- a/ext/afform/html/CRM/AfformHtml/Page/HtmlEditor.php +++ b/ext/afform/html/CRM/AfformHtml/Page/HtmlEditor.php @@ -3,12 +3,21 @@ use CRM_AfformHtml_ExtensionUtil as E; class CRM_AfformHtml_Page_HtmlEditor extends CRM_Core_Page { + const MONACO_DIR = 'node_modules/monaco-editor/min/vs'; + public function run() { - // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml - CRM_Utils_System::setTitle(E::ts('HtmlEditor')); + CRM_Utils_System::setTitle(E::ts('Afform HTML Editor')); - // Example: Assign a variable for use in a template - $this->assign('currentTime', date('Y-m-d H:i:s')); + CRM_Core_Region::instance('html-header')->add([ + 'markup' => '', + ]); + Civi::resources() + ->addVars('afform_html', [ + 'paths' => [ + 'vs' => E::url(self::MONACO_DIR), + ], + ]) + ->addScriptFile(E::LONG_NAME, self::MONACO_DIR . '/loader.js', CRM_Core_Resources::DEFAULT_WEIGHT, 'html-header'); parent::run(); } diff --git a/ext/afform/html/templates/CRM/AfformHtml/Page/HtmlEditor.tpl b/ext/afform/html/templates/CRM/AfformHtml/Page/HtmlEditor.tpl index 5ce6525659..df123dada3 100644 --- a/ext/afform/html/templates/CRM/AfformHtml/Page/HtmlEditor.tpl +++ b/ext/afform/html/templates/CRM/AfformHtml/Page/HtmlEditor.tpl @@ -1,7 +1,27 @@ -

This new page is generated by CRM/AfformHtml/Page/HtmlEditor.php

+ -{* Example: Display a variable directly *} -

The current time is {$currentTime}

+ +
-{* Example: Display a translated string -- which happens to include a variable *} -

{ts 1=$currentTime}(In your native language) The current time is %1.{/ts}

+ -- 2.25.1