-
Notifications
You must be signed in to change notification settings - Fork 72
[CMS Team 3] Sprint 1 #7
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
Changes from all commits
a8d4f7c
4868df5
7f6ced2
d01d65f
65549dd
f4367d0
fba630d
25d86c8
c9eccf1
3a4dabb
047325a
7c92238
cfb5793
49a1178
0100140
20fda9f
622e6c0
265ddf9
82973ec
b8cac1c
c3755db
742958c
09a455c
9a562cc
b1f1d0a
cf80c24
80c91f0
5899136
08ec99f
f307166
6df233a
c4b1282
6ed8157
9575f4a
4487d1a
8ead1a1
072a124
83a6383
3787df3
6e59cd0
5432346
2172524
68c41ae
d11be02
c9107b2
bdf4599
77f07af
b0ed495
37715f0
c23dafc
735ba54
1843615
adb1bb4
ccd738c
ce1168e
127cdca
ff02415
73b0b71
1c3c2e6
c721098
a9a77c8
cb71bfd
84238f3
b73363b
9f2abd4
2ded2dd
92e7f2f
70d130d
e266d82
2a75e13
208a018
9b79639
f57a030
e7e6ae0
cb3b8a9
8ee25e9
e385e9b
787092c
e955d9e
ad6f293
85570af
08cf85e
6111bff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\PageBuilder\Block\Adminhtml\System\Config; | ||
|
||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class EnableField extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
/** | ||
* @var \Magento\Framework\Serialize\Serializer\Json | ||
*/ | ||
private $json; | ||
|
||
/** | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param \Magento\Framework\Serialize\Serializer\Json $json | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Magento\Framework\Serialize\Serializer\Json $json, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->json = $json; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
$html = parent::_getElementHtml($element); | ||
$enablePageBuilderSelector = '#cms_pagebuilder_enabled'; | ||
|
||
$jsString = '<script type="text/x-magento-init"> {"' . | ||
$enablePageBuilderSelector . '": { | ||
"Magento_PageBuilder/js/system/config/enable-field": {"modalTitleText": ' . | ||
$this->json->serialize($this->getModalTitleText()) . ', "modalContentBody": ' . | ||
$this->json->serialize($this->getModalContentBody()) | ||
. '}}}</script>'; | ||
|
||
$html .= $jsString; | ||
return $html; | ||
} | ||
|
||
/** | ||
* Get text for the modal title heading when user switches to disable | ||
* | ||
* @return string | ||
*/ | ||
private function getModalTitleText() | ||
{ | ||
return __('Are You Sure You Want to Turn Off Page Builder?'); | ||
} | ||
|
||
/** | ||
* Get HTML for the modal content body when user switches to disable | ||
* | ||
* @return string | ||
*/ | ||
private function getModalContentBody() | ||
{ | ||
$templateFileName = $this->getTemplateFile( | ||
'Magento_PageBuilder::system/config/enableField/modalContentBody.phtml' | ||
); | ||
|
||
return $this->fetchView($templateFileName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,32 @@ | |
|
||
class Editor extends \Magento\Framework\Data\Form\Element\Editor | ||
{ | ||
/** | ||
* @var \Magento\PageBuilder\Model\State | ||
*/ | ||
private $pageBuilderState; | ||
|
||
/** | ||
* Editor constructor. | ||
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement | ||
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection | ||
* @param \Magento\Framework\Escaper $escaper | ||
* @param \Magento\PageBuilder\Model\State $pageBuilderState | ||
* @param array $data | ||
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Data\Form\Element\Factory $factoryElement, | ||
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, | ||
\Magento\Framework\Escaper $escaper, | ||
\Magento\PageBuilder\Model\State $pageBuilderState, | ||
$data = [], | ||
\Magento\Framework\Serialize\Serializer\Json $serializer = null | ||
) { | ||
$this->pageBuilderState = $pageBuilderState; | ||
parent::__construct($factoryElement, $factoryCollection, $escaper, $data); | ||
} | ||
|
||
/** | ||
* Return HTML button to toggling WYSIWYG | ||
* | ||
|
@@ -16,12 +42,11 @@ class Editor extends \Magento\Framework\Data\Form\Element\Editor | |
protected function _getToggleButtonHtml($visible = true) | ||
{ | ||
$buttonHtml = ''; | ||
if ($this->getConfig()->getData('pagebuilder_button') !== false) { | ||
if ($this->getConfig()->getData('pagebuilder_button') === true && $this->isPageBuilderUsed()) { | ||
$buttonHtml .= $this->_getButtonHtml( | ||
[ | ||
'title' => $this->translate('Enable Advanced CMS'), | ||
'class' => 'magento-pagebuilder init-magento-pagebuilder action-default scalable action' | ||
. ' action-secondary', | ||
'title' => $this->translate('Edit with Page Builder'), | ||
'class' => 'magento-pagebuilder init-magento-pagebuilder action-default scalable action', | ||
'id' => 'magento-pagebuilder' . $this->getHtmlId() | ||
] | ||
); | ||
|
@@ -37,6 +62,17 @@ protected function _getToggleButtonHtml($visible = true) | |
return $buttonHtml . parent::_getToggleButtonHtml($visible); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isEnabled() | ||
{ | ||
if ($this->isPageBuilderUsed()) { | ||
return true; | ||
} | ||
return parent::isEnabled(); | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of your task, but could you please remove this method? |
||
* Is the stage aspect of the system enabled | ||
* | ||
|
@@ -46,4 +82,28 @@ protected function isStageEnabled() | |
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getInlineJs($jsSetupObject, $forceLoad) | ||
{ | ||
if ($this->isPageBuilderUsed()) { | ||
return ''; | ||
} | ||
|
||
return parent::getInlineJs($jsSetupObject, $forceLoad); | ||
} | ||
|
||
/** | ||
* Return if page builder will be used instead of wysiwyg editor | ||
* | ||
* @return bool | ||
*/ | ||
private function isPageBuilderUsed() | ||
{ | ||
$config = $this->getConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we check activeEditorPath? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to simplify that condition in the feature sprint |
||
return $config->getData('activeEditorPath') === 'Magento_PageBuilder/pageBuilderAdapter' | ||
&& $config->getData('enable_pagebuilder') !== false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
|
||
namespace Magento\PageBuilder\Model; | ||
|
||
class State | ||
{ | ||
/** | ||
* @var \Magento\PageBuilder\Model\Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* State constructor. | ||
* @param Config $config | ||
*/ | ||
public function __construct(Config $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Returns information if use page builder based on system configuration and xml configuration | ||
* @param $isPageBuilderUsed | ||
* @return bool | ||
*/ | ||
public function isPageBuilderInUse($isPageBuilderUsed) | ||
{ | ||
return $isPageBuilderUsed || !$this->config->isEnabled(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
Magento_PageBuilder module provides an alternative interface for building content. | ||
# Magento_PageBuilder module | ||
|
||
The Magento_PageBuilder module provides an enhancement for the default Magento WYSIWYG editor. It installs an alternative editor in the Admin area for building content. | ||
|
||
The PageBuilder editor can be used on the following content pages: | ||
|
||
* Category Pages | ||
* CMS Pages | ||
* CMS Blocks | ||
* Dynamic Blocks | ||
|
||
## Enable the module | ||
|
||
The PageBuilder module and the editor is enabled by default after installation. | ||
|
||
The editor itself is enabled globally in the Admin area under *Stores > Configuration > Content Management > Advanced Content Tool > Enable Page Builder*. | ||
This setting determines the `is_pagebuilder_enabled` configuration value. | ||
|
||
## Disable the module | ||
|
||
You can disable the PageBuilder module for a specific field by adding the following entry to a field configuration in an XML configuration file: | ||
|
||
``` | ||
<item name="wysiwygConfigData" xsi:type="array"> | ||
<item name="enable_pagebuilder" xsi:type="boolean">false</item> | ||
</item> | ||
``` | ||
|
||
### Example | ||
|
||
The following example disables the PageBuilder editor for the content field. | ||
|
||
``` | ||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | ||
<fieldset name="content" sortOrder="10"> | ||
<field name="content" formElement="wysiwyg"> | ||
<argument name="data" xsi:type="array"> | ||
<item name="config" xsi:type="array"> | ||
<item name="source" xsi:type="string">page</item> | ||
<item name="wysiwygConfigData" xsi:type="array"> | ||
<item name="enable_pagebuilder" xsi:type="boolean">false</item> | ||
</item> | ||
</item> | ||
</argument> | ||
</field> | ||
</fieldset> | ||
</form> | ||
``` | ||
|
||
**Note:** Disabling the editor this way overrides the value of `is_pagebuilder_enabled` for the specified field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't capitalise each word in this string, it becomes more difficult to read.
I'd propose:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was requirement from Ievgen and Olena. I will check with them