magento2
magento2 copied to clipboard
The zero-valued parameters are missed in the widget code, generated by the TinyMCE editor
Hi guys, When insert a widget via TinyMCE editor, we can't not get param with values is zero in the widget short code generated. I have detected and see the root of issue at below function: (vendor/magento/module-widget/Model/Widget.php)
public function getWidgetDeclaration($type, $params = [], $asIs = true)
{
$directive = '{{widget type="' . $type . '"';
foreach ($params as $name => $value) {
// Retrieve default option value if pre-configured
if ($name == 'conditions') {
$name = 'conditions_encoded';
$value = $this->conditionsHelper->encode($value);
} elseif (is_array($value)) {
$value = implode(',', $value);
} elseif (trim($value) == '') {
$widget = $this->getConfigAsObject($type);
$parameters = $widget->getParameters();
if (isset($parameters[$name]) && is_object($parameters[$name])) {
$value = $parameters[$name]->getValue();
}
}
if ($value) {
$directive .= sprintf(' %s="%s"', $name, $value);
}
}
$directive .= '}}';
if ($asIs) {
return $directive;
}
$html = sprintf(
'<img id="%s" src="%s" title="%s">',
$this->idEncode($directive),
$this->getPlaceholderImageUrl($type),
$this->escaper->escapeUrl($directive)
);
return $html;
}
We have change to:
public function getWidgetDeclaration($type, $params = [], $asIs = true)
{
$directive = '{{widget type="' . $type . '"';
foreach ($params as $name => $value) {
// Retrieve default option value if pre-configured
if ($name == 'conditions') {
$name = 'conditions_encoded';
$value = $this->conditionsHelper->encode($value);
} elseif (is_array($value)) {
$value = implode(',', $value);
} elseif (trim($value) == '') {
$widget = $this->getConfigAsObject($type);
$parameters = $widget->getParameters();
if (isset($parameters[$name]) && is_object($parameters[$name])) {
$value = $parameters[$name]->getValue();
}
}
// if ($value) {
$directive .= sprintf(' %s="%s"', $name, $value);
// }
}
$directive .= '}}';
if ($asIs) {
return $directive;
}
$html = sprintf(
'<img id="%s" src="%s" title="%s">',
$this->idEncode($directive),
$this->getPlaceholderImageUrl($type),
$this->escaper->escapeUrl($directive)
);
return $html;
}
Please have a look. Regards, Quynhvv.
Confirmed, internal issue MAGETWO-54159
Closed as has been already fixed in 5099ab40 b3e4c3bb2 e7ae8f3c