Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CDN optional & minor code improvements #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
composer.lock
js/monacoeditor/dist
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Monaco HTML Editor for Magento 1 / OpenMage

## Requirements
- [OpenMage](https://github.com/OpenMage/magento-lts) / Magento 1.9.x
- PHP 7.4 / 8.x
Expand Down
22 changes: 11 additions & 11 deletions app/code/local/MM/MonacoEditor/Block/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ class MM_MonacoEditor_Block_Init extends Mage_Core_Block_Template
{
/**
* return json encoded array of textareas id and language
* @return string
*/
public function getTextAreas()
public function getTextAreas(): string
{
$textareas = [];
$controller = Mage::app()->getRequest()->getControllerName();

switch($controller){
switch ($controller) {
case 'cms_page':
$textareas = [
[
Expand All @@ -36,16 +35,17 @@ public function getTextAreas()
];
break;
}
return Zend_Json::encode($textareas,false,array('enableJsonExprFinder'=>true));

return Zend_Json::encode($textareas, false, ['enableJsonExprFinder' => true]);
}

/**
* return true if wysiwyg is enabled by default
*
* @return boolean
*/
public function isWysiwygEnabledByDefault()
public function isWysiwygEnabledByDefault(): bool
{
return Mage::getStoreConfig('cms/wysiwyg/enabled') === 'enabled';
}

public function getEditorJsUrl($fileName = ''): string
{
return Mage::getStoreConfig('cms/wysiwyg/enabled') == 'enabled';
return Mage::getStoreConfig('cms/mm_monacoeditor/editorjs_url_prefix') . $fileName;
}
}
50 changes: 11 additions & 39 deletions app/code/local/MM/MonacoEditor/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,74 +1,46 @@
<?php
class MM_MonacoEditor_Helper_Data extends Mage_Core_Helper_Abstract
{

const XML_PATH_CONFIG_TAILWINDCSS_ENABLED = 'cms/mm_monacoeditor/tailwindcss';
const XML_PATH_CONFIG_TAILWINDCSS_PREFIX_ENABLED = 'cms/mm_monacoeditor/tailwindcss_prefix';
const XML_PATH_CONFIG_TAILWINDCSS_PREFIX = 'cms/mm_monacoeditor/tailwindcss_prefix_value';
const XML_PATH_CONFIG_DISABLE_WYSIWYG_BLOCKS = 'cms/mm_monacoeditor/disable_wysywyg_static_block';
const XML_PATH_CONFIG_DISABLE_WYSIWYG_PAGES = 'cms/mm_monacoeditor/disable_wysywyg_static_page';

/**
* return true if tailwindcss is enabled
*
* @param int $storeId
* @return boolean
*/
public function isTailwindcssEnabled($storeId = null)
public function isTailwindcssEnabled(int $storeId = null): bool
{
return Mage::getStoreConfigFlag(self::XML_PATH_CONFIG_TAILWINDCSS_ENABLED, $storeId);
}

/**
* return true if tailwindcss prefix is enabled
*
* @param int $storeId
* @return boolean
*/
public function isTailwindcssPrefixEnabled($storeId = null)
public function isTailwindcssPrefixEnabled(int $storeId = null): bool
{
return Mage::getStoreConfigFlag(self::XML_PATH_CONFIG_TAILWINDCSS_PREFIX_ENABLED, $storeId);
}

/**
* return tailwindcss prefix value
* @return string
*/
public function getTailwindcssPrefix($storeId = null)
public function getTailwindcssPrefix(int $storeId = null): string
{
return Mage::getStoreConfig(self::XML_PATH_CONFIG_TAILWINDCSS_PREFIX, $storeId);
}

/**
* return disabled wysiwyg blocks
*
* @param int $storeId
* @return array
*/
public function getDisabledWysiwygBlocks($storeId = null)
/** @return array<string> */
public function getDisabledWysiwygBlocks(int $storeId = null): array
{
$disabledEntityIds = Mage::getStoreConfig(self::XML_PATH_CONFIG_DISABLE_WYSIWYG_BLOCKS, $storeId);
if (!$disabledEntityIds) {
return [];
}
$disabledEntityIds = explode(',', $disabledEntityIds);
return $disabledEntityIds;

return explode(',', $disabledEntityIds);
}

/**
* return disabled wysiwyg pages
*
* @param int $storeId
* @return array
*/
public function getDisabledWysiwygPages($storeId = null)
/** @return array<string> */
public function getDisabledWysiwygPages(int $storeId = null): array
{
$disabledEntityIds = Mage::getStoreConfig(self::XML_PATH_CONFIG_DISABLE_WYSIWYG_PAGES, $storeId);
if (!$disabledEntityIds) {
return [];
}
$disabledEntityIds = explode(',', $disabledEntityIds);
return $disabledEntityIds;
}

return explode(',', $disabledEntityIds);
}
}
31 changes: 10 additions & 21 deletions app/code/local/MM/MonacoEditor/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
<?php
class MM_MonacoEditor_Model_Observer {

/**
* Disable WYSIWYG editor for pages and static blocks
*
* @param Varien_Event_Observer $observer
* @return void
*/
public function disableWysywygEditor(Varien_Event_Observer $observer)
{
if (!$this->_checkEntityisDisabled()) {
final class MM_MonacoEditor_Model_Observer
{
public function disableWysywygEditor(Varien_Event_Observer $observer): void
{
if (! $this->_shouldEntityBeDisabled()) {
return;
}
$config = $observer->getConfig();

$config = $observer->getConfig();
$config->setEnabled(false);
}

/**
* Disable WYSIWYG editor for pages and static blocks
*
* @return boolean
*/
private function _checkEntityisDisabled()
private function _shouldEntityBeDisabled(): bool
{
$controller = Mage::app()->getRequest()->getControllerName();

switch($controller){
switch ($controller) {
case 'cms_page':
return in_array(Mage::app()->getRequest()->getParam('page_id'), Mage::helper('mm_monacoeditor')->getDisabledWysiwygPages());
break;
case 'cms_block':
return in_array(Mage::app()->getRequest()->getParam('block_id'), Mage::helper('mm_monacoeditor')->getDisabledWysiwygBlocks());
break;
}

return false;
}
}

This file was deleted.

4 changes: 4 additions & 0 deletions app/code/local/MM/MonacoEditor/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<version>1.0.0</version>
</MM_MonacoEditor>
</modules>

<global>
<blocks>
<mm_monacoeditor>
Expand All @@ -22,6 +23,7 @@
</mm_monacoeditor>
</models>
</global>

<adminhtml>
<layout>
<updates>
Expand All @@ -42,10 +44,12 @@
</cms_wysiwyg_config_prepare>
</events>
</adminhtml>

<default>
<cms>
<mm_monacoeditor>
<enabled>1</enabled>
<editorjs_url_prefix>https://unpkg.com/monaco-editor@latest/min/</editorjs_url_prefix>
<tailwindcss>1</tailwindcss>
<tailwindcss_prefix_value>tw-</tailwindcss_prefix_value>
</mm_monacoeditor>
Expand Down
3 changes: 1 addition & 2 deletions app/code/local/MM/MonacoEditor/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
<label>Disable Wysywyg Cms Pages</label>>
<frontend_type>multiselect</frontend_type>
<sort_order>51</sort_order>
<source_model>mm_monacoeditor/system_config_source_cms_pages</source_model>

<source_model>adminhtml/system_config_source_cms_page</source_model>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
Expand Down
15 changes: 14 additions & 1 deletion app/design/adminhtml/default/default/layout/mm/monacoeditor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,23 @@

<mm_monacoeditor>
<reference name="head">
<action method="addJs">
<action method="addCss">
<stylesheet>mm_monacoeditor.css</stylesheet>
</action>
<action method="addJs" ifconfig="cms/mm_monacoeditor/tailwindcss">
<script>monacoeditor/monaco-tailwindcss.min.js</script>
<type>type="module"</type>
</action>
<block type="core/text" name="mm_monacoeditor_monaco_editor_external_js">
<action method="setText">
<text><![CDATA[<script type="text/javascript" src="https://unpkg.com/monaco-editor@latest/min/vs/loader.js" defer></script>]]></text>
</action>
</block>
<block type="core/text" name="mm_monacoeditor_emmet_monaco_external_js">
<action method="setText">
<text><![CDATA[<script type="text/javascript" src="https://unpkg.com/emmet-monaco-es/dist/emmet-monaco.min.js" defer></script>]]></text>
</action>
</block>
</reference>
<reference name="content" after="-">
<block type="mm_monacoeditor/init" template="mm/monacoeditor/script.phtml"/>
Expand Down
Loading