Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorvansach committed Jun 20, 2019
1 parent da5ef73 commit 0c70884
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Plugin/Magento/Ui/Component/Wysiwyg/ConfigPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*/
namespace Magefan\WysiwygAdvanced\Plugin\Magento\Ui\Component\Wysiwyg;

/**
* Class ConfigPlugin
* @package Magefan\WysiwygAdvanced\Plugin\Magento\Ui\Component\Wysiwyg
*/
class ConfigPlugin
{

/**
* @var \Magento\Ui\Block\Wysiwyg\ActiveEditor
*/
protected $activeEditor;

/**
* ConfigPlugin constructor.
* @param \Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor
*/
public function __construct(\Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor)
{
$this->activeEditor = $activeEditor;
}

/**
* Return WYSIWYG configuration
*
* @param \Magento\Ui\Component\Wysiwyg\ConfigInterface $configInterface
* @param \Magento\Framework\DataObject $result
* @return \Magento\Framework\DataObject
*/
public function afterGetConfig(
\Magento\Ui\Component\Wysiwyg\ConfigInterface $configInterface,
\Magento\Framework\DataObject $result
) {
// Get current wysiwyg adapter's path
$editor = $this->activeEditor->getWysiwygAdapterPath();

// Is the current wysiwyg tinymce v4?
if(strpos($editor,'tinymce4Adapter')){

if (($result->getDataByPath('settings/menubar')) || ($result->getDataByPath('settings/toolbar')) || ($result->getDataByPath('settings/plugins'))){
// do not override ui_element config (unsure if this is needed)
return $result;
}

$settings = $result->getData('settings');

if (!is_array($settings)) {
$settings = [];
}

// configure tinymce settings
$settings['menubar'] = true;
$settings['toolbar'] = 'undo redo | styleselect | fontsizeselect | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | image | code';
$settings['plugins'] = 'textcolor image code';

$result->setData('settings', $settings);
return $result;
} else{ // don't make any changes if the current wysiwyg editor is not tinymce 4
return $result;
}
}
}
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "magefan/module-wysiwyg-advanced",
"description": "Extend TinyMCE 4 in Magento 2",
"type": "magento2-module",
"version": "2.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magefan\\WysiwygAdvanced\\": ""
}
}
}
13 changes: 13 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Ui\Component\Wysiwyg\ConfigInterface">
<plugin disabled="false" name="Magefan_WysiwygAdvanced_Plugin_Magento_Ui_Component_Wysiwyg_ConfigInterface" sortOrder="10" type="Magefan\WysiwygAdvanced\Plugin\Magento\Ui\Component\Wysiwyg\ConfigPlugin"/>
</type>
</config>
15 changes: 15 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magefan_WysiwygAdvanced" setup_version="2.0.0">
<sequence>
<module name="Magento_Ui"/>
</sequence>
</module>
</config>
11 changes: 11 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*/

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magefan_WysiwygAdvanced',
__DIR__
);

0 comments on commit 0c70884

Please sign in to comment.