I try to add a wysiwyg editor to my custom widget.
I added the field to my widget.xml
<parameter name="content" xsi:type="block" required="false" visible="true" sort_order="60">
<label>Content</label>
<block class="TestCustomBlockWidgetEditor" />
</parameter>
and this is my Editor.php :
<?php
namespace TestCustomBlockWidget;
use MagentoFrameworkViewElementTemplate;
use MagentoWidgetBlockBlockInterface;
class Editor extends Template implements BlockInterface
{
/**
* @var MagentoCmsModelWysiwygConfig
*/
protected $_wysiwygConfig;
/**
* @var Factory
*/
protected $_factoryElement;
/**
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param array $data
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkDataFormElementFactory $factoryElement,
MagentoCmsModelWysiwygConfig $wysiwygConfig,
$data = []
) {
$this->_factoryElement = $factoryElement;
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $data);
}
/**
* Prepare chooser element HTML
*
* @param MagentoFrameworkDataFormElementAbstractElement $element Form Element
* @return MagentoFrameworkDataFormElementAbstractElement
*/
public function prepareElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
{
$editor = $this->_factoryElement->create('editor', ['data' => $element->getData()])
->setLabel('')
->setForm($element->getForm())
->setWysiwyg(true)
->setConfig($this->_wysiwygConfig->getConfig(['add_variables' => false, 'add_widgets' => false]));
if ($element->getRequired()) {
$editor->addClass('required-entry');
}
$element->setData(
'after_element_html', $this->_getAfterElementHtml() . $editor->getElementHtml()
);
return $element;
}
/**
* @return string
*/
protected function _getAfterElementHtml()
{
$html = <<<HTML
<style>
.admin__field-control.control .control-value {
display: none !important;
}
</style>
HTML;
return $html;
}
}
If i try to get the Editor value to my frontend like this :
<?= $block->getData('content');?>
or like this :
<?= $block->escapeHtml($block->getData('content')) ?>
it shows the HTML Tags in Frontend.
How can i “allow” html tags for my wysiwyg editor?