Skip to content

Commit

Permalink
MAGETWO-72114: TinyMCE v4.6 as a native WYSIWYG editor
Browse files Browse the repository at this point in the history
- Squashed merge of Sprint 2, includes 72207, 70412, 72120, 81766, 51829, 72365, 72137, and 71249
- Add TinyMCE4 library to Magento core
- Move TinyMCE3 to new compatibility module which will be removed from core
- Add WYSIWYG fascade and adapter to support easy swapping of editors
- Make Editor configuration easily extensible
- Fix bug in Category Content area to remove extreneous buttons
  • Loading branch information
tjwiebell authored and irenelagno committed Dec 12, 2017
1 parent 4bbb256 commit 14646d2
Show file tree
Hide file tree
Showing 485 changed files with 3,470 additions and 556 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ atlassian*
/.php_cs.cache
/grunt-config.json
/dev/tools/grunt/configs/local-themes.js

/pub/media/*.*
!/pub/media/.htaccess
/pub/media/attribute/*
Expand Down
12 changes: 0 additions & 12 deletions app/code/Magento/Catalog/Block/Adminhtml/Helper/Form/Wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ public function getAfterElementHtml()
var config = $config,
editor;
jQuery.extend(config, {
settings: {
theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' +
'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code',
theme_advanced_buttons2: null,
theme_advanced_buttons3: null,
theme_advanced_buttons4: null,
theme_advanced_statusbar_location: null
},
files_browser_window_url: false
});
editor = new tinyMceWysiwygSetup(
'{$this->getHtmlId()}',
config
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function isUsingStaticUrlsAllowed()
return $this->scopeConfig->isSetFlag(
self::CONFIG_USE_STATIC_URLS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_storeId
(int) $this->_storeId
);
}

Expand Down
12 changes: 8 additions & 4 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Form\Field;
use Magento\Ui\DataProvider\EavValidationRules;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

/**
* Class DataProvider
Expand All @@ -33,7 +34,7 @@
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @since 101.0.0
*/
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
{
/**
* @var string
Expand Down Expand Up @@ -160,6 +161,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param CategoryFactory $categoryFactory
* @param array $meta
* @param array $data
* @param PoolInterface $pool
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -174,7 +176,8 @@ public function __construct(
\Magento\Framework\App\RequestInterface $request,
CategoryFactory $categoryFactory,
array $meta = [],
array $data = []
array $data = [],
PoolInterface $pool = null
) {
$this->eavValidationRules = $eavValidationRules;
$this->collection = $categoryCollectionFactory->create();
Expand All @@ -185,7 +188,7 @@ public function __construct(
$this->request = $request;
$this->categoryFactory = $categoryFactory;

parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
}

/**
Expand All @@ -202,7 +205,7 @@ public function getMeta()
if ($category) {
$meta = $this->addUseDefaultValueCheckbox($category, $meta);
}

// Default and custom settings
return $meta;
}

Expand Down Expand Up @@ -305,6 +308,7 @@ public function getData()

$this->loadedData[$category->getId()] = $categoryData;
}

return $this->loadedData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Framework\Registry;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\DataProvider\EavValidationRules;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -72,6 +73,11 @@ class DataProviderTest extends \PHPUnit\Framework\TestCase
*/
private $fileInfo;

/**
* @var PoolInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $modifierPool;

protected function setUp()
{
$this->eavValidationRules = $this->getMockBuilder(EavValidationRules::class)
Expand Down Expand Up @@ -120,6 +126,8 @@ protected function setUp()
$this->fileInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();

$this->modifierPool = $this->getMockBuilder(PoolInterface::class)->getMockForAbstractClass();
}

/**
Expand All @@ -137,6 +145,8 @@ private function getModel()
->willReturn($this->eavEntityMock);

$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

/** @var DataProvider $model */
$model = $objectManager->getObject(
DataProvider::class,
[
Expand All @@ -147,6 +157,7 @@ private function getModel()
'eavConfig' => $this->eavConfig,
'request' => $this->request,
'categoryFactory' => $this->categoryFactory,
'pool' => $this->modifierPool
]
);

Expand Down Expand Up @@ -336,6 +347,10 @@ public function testGetMetaWithoutParentInheritanceResolving()
$categoryMock->expects($this->never())
->method('getParentId');

$this->modifierPool->expects($this->once())
->method('getModifiersInstances')
->willReturn([]);

$this->getModel()->getMeta();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,5 @@ public function __construct(

$config['wysiwyg'] = (bool)$attrRepository->get($data['name'])->getIsWysiwygEnabled();
parent::__construct($context, $formFactory, $wysiwygConfig, $components, $data, $config);
$this->setData($this->prepareData($this->getData()));
}

/**
* Prepare wysiwyg content
*
* @param array $data
* @return array
*/
private function prepareData($data)
{
if ($this->editor->isEnabled()) {
$data['config']['content'] .= $this->getWysiwygButtonHtml();
}
return $data;
}

/**
* Return wysiwyg button html
*
* @return string
*/
private function getWysiwygButtonHtml()
{
return $this->layout->createBlock(
Button::class,
'',
[
'data' => [
'label' => __('WYSIWYG Editor'),
'type' => 'button',
'class' => 'action-wysiwyg',
'onclick' => 'catalogWysiwygEditor.open(\'' . $this->backendHelper->getUrl(
'catalog/product/wysiwyg'
) . '\', \'' . $this->editor->getHtmlId() . '\')',
]
]
)->toHtml();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Ui\DataProvider\Category\Form\Modifier;

use Magento\Ui\DataProvider\Modifier\ModifierInterface;

class WysiwygConfigModifier implements ModifierInterface
{
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritdoc}
*/
public function modifyMeta(array $meta)
{
$settings = [
'height' => '100px',
'add_variables' => false,
'add_widgets' => false,
'add_images' => true,
'add_directives' => true
];

$meta['content']['children']['description']['arguments']['data']['config']['wysiwygConfigData']
= $settings;

return $meta;
}
}
15 changes: 15 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@
<argument name="scopeOverriddenValue" xsi:type="object">Magento\Catalog\Model\Attribute\ScopeOverriddenValue</argument>
</arguments>
</type>
<virtualType name="UiModifierPool" type="Magento\Ui\DataProvider\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="wysiwyg-category" xsi:type="array">
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Category\Form\Modifier\WysiwygConfigModifier</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Model\Category\DataProvider">
<arguments>
<argument name="pool" xsi:type="object">UiModifierPool</argument>
</arguments>
</type>
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,6 @@
</formElements>
</field>
<field name="description" template="ui/form/field" sortOrder="50" formElement="wysiwyg">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="wysiwygConfigData" xsi:type="array">
<item name="settings" xsi:type="array">
<item name="theme_advanced_buttons1" xsi:type="string">bold,italic,|,justifyleft,justifycenter,justifyright,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code</item>
<item name="theme_advanced_buttons2" xsi:type="boolean">false</item>
<item name="theme_advanced_buttons3" xsi:type="boolean">false</item>
<item name="theme_advanced_buttons4" xsi:type="boolean">false</item>
<item name="theme_advanced_statusbar_location" xsi:type="boolean">false</item>
</item>
<item name="files_browser_window_url" xsi:type="boolean">false</item>
<item name="height" xsi:type="string">100px</item>
<item name="toggle_button" xsi:type="boolean">false</item>
<item name="add_variables" xsi:type="boolean">false</item>
<item name="add_widgets" xsi:type="boolean">false</item>
<item name="add_images" xsi:type="boolean">false</item>
<item name="add_directives" xsi:type="boolean">true</item>
</item>
<item name="source" xsi:type="string">category</item>
</item>
</argument>
<settings>
<label translate="true">Description</label>
<dataScope>description</dataScope>
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Catalog/view/adminhtml/web/js/edit-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

require([
'jquery',
'tinymce',
'Magento_Ui/js/modal/confirm',
'Magento_Ui/js/modal/alert',
'loadingPopup',
'mage/backend/floating-header'
], function (jQuery, tinyMCE, confirm) {
], function (jQuery, confirm) {
'use strict';

/**
Expand Down
9 changes: 6 additions & 3 deletions app/code/Magento/Cms/Model/Block/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

/**
* Class DataProvider
*/
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
{
/**
* @var \Magento\Cms\Model\ResourceModel\Block\Collection
Expand All @@ -36,6 +37,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param string $requestFieldName
* @param CollectionFactory $blockCollectionFactory
* @param DataPersistorInterface $dataPersistor
* @param PoolInterface|null $pool
* @param array $meta
* @param array $data
*/
Expand All @@ -46,11 +48,12 @@ public function __construct(
CollectionFactory $blockCollectionFactory,
DataPersistorInterface $dataPersistor,
array $meta = [],
array $data = []
array $data = [],
PoolInterface $pool = null
) {
$this->collection = $blockCollectionFactory->create();
$this->dataPersistor = $dataPersistor;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/Cms/Model/Config/Source/Wysiwyg/Editor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Config\Source\Wysiwyg;

/**
* Configuration source model for Wysiwyg toggling
*/
class Editor implements \Magento\Framework\Option\ArrayInterface
{
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return [
['value' => 'tinymce', 'label' => __('TinyMCE 4')]
];
}
}
9 changes: 6 additions & 3 deletions app/code/Magento/Cms/Model/Page/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

/**
* Class DataProvider
*/
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
{
/**
* @var \Magento\Cms\Model\ResourceModel\Page\Collection
Expand All @@ -34,6 +35,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param DataPersistorInterface $dataPersistor
* @param PoolInterface|null $pool
* @param array $meta
* @param array $data
*/
Expand All @@ -44,11 +46,12 @@ public function __construct(
CollectionFactory $pageCollectionFactory,
DataPersistorInterface $dataPersistor,
array $meta = [],
array $data = []
array $data = [],
PoolInterface $pool = null
) {
$this->collection = $pageCollectionFactory->create();
$this->dataPersistor = $dataPersistor;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
$this->meta = $this->prepareMeta($this->meta);
}

Expand Down
Loading

0 comments on commit 14646d2

Please sign in to comment.