-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Magento 2.1 EE: simplexml_load_string() error in custom widget #6594
Comments
@enrico69 thank you for your feedback. |
Sorry. That's done. |
Could you please paste your xml for custom widget here? |
<?xml version="1.0" encoding="UTF-8"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="myclient_corporateWidget" class="Myclient\CorporateWidget\Block\Widget\CorporateWidget">
<label translate="true">Myclient Corporate Widget</label>
<description>Widget containing informations about Myclient</description>
<parameters>
<parameter name="widgetTitle" xsi:type="text" visible="true" sort_order="10" >
<label translate="true">Title</label>
</parameter>
<parameter name="videoHtmlCode" xsi:type="text" visible="true" sort_order="10" >
<label translate="true">Video Url</label>
</parameter>
<parameter name="logoFile" xsi:type="text" visible="true" sort_order="10" >
<label translate="true">Logo</label>
</parameter>
<parameter name="picture1File" xsi:type="select" source_model="Myclient\CorporateWidget\Model\Listing\Picture" visible="true" sort_order="10" >
<label translate="true">Picture #1</label>
</parameter>
<parameter name="pic1Text" xsi:type="block" visible="true" sort_order="10" >
<label translate="true">Picture #1 description</label>
<block class="Mycompany\Tools\Block\Adminhtml\Widget\TextArea" />
</parameter>
<parameter name="picture2File" xsi:type="select" source_model="Myclient\CorporateWidget\Model\Listing\Picture" visible="true" sort_order="10" >
<label translate="true">Picture #2</label>
</parameter>
<parameter name="pic2Text" xsi:type="block" visible="true" sort_order="10" >
<label translate="true">Picture #2 description</label>
<block class="Mycompany\Tools\Block\Adminhtml\Widget\TextArea" />
</parameter>
<parameter name="picture3File" xsi:type="select" source_model="Myclient\CorporateWidget\Model\Listing\Picture" visible="true" sort_order="10" >
<label translate="true">Picture #3</label>
</parameter>
<parameter name="pic3Text" xsi:type="block" visible="true" sort_order="10" >
<label translate="true">Picture #3 description</label>
<block class="Mycompany\Tools\Block\Adminhtml\Widget\TextArea" />
</parameter>
</parameters>
</widget>
</widgets> |
Can't reproduce with your xml but without your classes. How do you add content right to your widget without a block? What layout update do you select? Maybe you have some non-default locale set? |
Hi <?php
namespace Mycompany\Tools\Block\Adminhtml\Widget;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Element;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Data\Form\Element\AbstractElement;
class TextArea extends Element
{
/**
* @var Factory
*/
protected $factoryElement;
/**
* @var Magento\Framework\Module\Dir\Reader
*/
protected $reader;
/**
*
* @param Context $context
* @param Factory $factoryElement
* @param type $data
*/
public function __construct(
Reader $reader,
Context $context,
Factory $factoryElement,
$data = []
) {
$this->factoryElement = $factoryElement;
$this->reader = $reader;
parent::__construct($context, $data);
}
/**
* Prepare chooser element HTML
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element Form Element
* @return \Magento\Framework\Data\Form\Element\AbstractElement
*/
public function prepareElementHtml(AbstractElement $element)
{
$textArea = $this->factoryElement->create('textarea', ['data' => $element->getData()])
->setId($element->getId())
->setForm($element->getForm())
->setClass('widget-option input-textarea admin__control-text');
if ($element->getRequired()) {
$textArea->addClass('required-entry');
}
$element->setData(
'after_element_html',
$this->_getAfterElementHtml() . $textArea->getElementHtml()
);
return $element;
}
/**
* @return string
*/
protected function _getAfterElementHtml()
{
$filePath = $this->reader->getModuleDir('view', 'Mycompany_Tools');
$filePath .= DIRECTORY_SEPARATOR . 'adminhtml' . DIRECTORY_SEPARATOR . 'templates'
. DIRECTORY_SEPARATOR . 'widget'. DIRECTORY_SEPARATOR . 'htmlAddition.php';
ob_start();
include $filePath;
return ob_get_clean();
}
} And here the CSS I add : <style>
.admin__field-control.control .control-value {
display: none !important;
}
</style> I followed a couple of tutorial in order to compensate the lack of TextArea field for the widgets. |
Is this still reproducible in latest release branch? |
We are closing this issue because it hasn’t been updated in more than two weeks. If you can still reproduce this issue, please create a new GitHub issue report. |
How to fix bug? |
@sevos1984 Can you please open this again? I'm on Magento 2.1.1 and I've got this error as well: Example: I've got some German texts that are too long, in a widget text field, so I want to skip them to the next line by using as a html entity. This breaks the entire site.
Now, problem is, this is added as a serialized array to the widget_instance. It instantly breaks your database. What I also found out that this mostly happens when you add data through Content > Widgets, not through adding widgets through pages. I suspect TinyMCE does some escaping itself. My guess is that the problem can be solved here, but I'm not sure.
|
I did find some sort of solution for this issue, although I'm not sure if its really a bug because technically those elements are invalid XML and shouldn't be use in widgets. However most clients do just put in these types of characters and then Magento converts them into HTML Entities on Save and this is just read straight into XML. If you put a preference on the You can do something like:
|
@antbates1991 your solution works. This isssue should be reopned as the problem still exists with Magento 2.1.6. |
@qbo-tech, the closed issues rarely get reopened here because they rarely get any attention from someone with an ability to reopen it. |
Internal ticket to track issue progress: MAGETWO-70469 |
For anyone who doesn't want to wait for 2.2.x you can use this small module to apply the fix https://github.com/WeareJH/m2-core-bug-simplexml-widget |
@antbates1991 Thank you - this worked for me as well. Since the entity protected function _loadXmlString($xmlString)
{
// Added bugfix from https://github.com/magento/magento2/issues/6594#issuecomment-283650111
$unescapedValues = [' ', 'é', 'à', 'ù', 'è', 'ô', '–'];
foreach ($unescapedValues as $value) {
// wrap in CDATA to escape
$xmlString = str_replace($value, "<![CDATA[$value]]>", $xmlString);
}
return simplexml_load_string($xmlString, 'Magento\Framework\View\Layout\Element');
} Helpful info to anyone else having the issue - you may need to add an additional item to the array based on your err msg. |
I run into this problem now after an update from Magento 2.1.5 to 2.2.6 :-( I'm not sure if this is intended behaviour, but what I find strange is that all the content of my WYSIWYG-editor is parsed as being "layout". If I look at the content of
Is this correct? Should my HTML be in the layout merger? Seems a little odd to me... |
Preconditions
Steps to reproduce
<p>Bonjour éàùè ô</p>
Expected result
Actual result
A warning is raised :
Exception #0 (Exception): Warning: simplexml_load_string(): Entity: line 1: parser error : Entity 'eacute' not defined in /var/www/xx/vendor/magento/framework/View/Model/Layout/Merge.php on line 493
Notes:
The text was updated successfully, but these errors were encountered: