Skip to content

Commit

Permalink
magento2/issues/12087: Changes for Widget class.
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Kilo committed Jul 6, 2020
1 parent f3a160c commit 7f0f260
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/code/Magento/Widget/Model/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public function getWidgetDeclaration($type, $params = [], $asIs = true)
if ($name == 'conditions') {
$name = 'conditions_encoded';
$value = $this->conditionsHelper->encode($value);
} elseif ($this->isTextType($widget, $name)) {
$value = $this->encodeReservedChars($value);
} elseif (is_array($value)) {
$value = implode(',', $value);
} elseif (trim($value) == '') {
Expand Down Expand Up @@ -456,4 +458,41 @@ protected function sortParameters($firstElement, $secondElement)
$bOrder = (int)$secondElement->getData('sort_order');
return $aOrder < $bOrder ? -1 : ($aOrder > $bOrder ? 1 : 0);
}

/**
* @param $string
* @return string|string[]
*/
private function encodeReservedChars($string)
{
$map = [
'{' => urlencode('{'),
'}' => urlencode('}')
];

return str_replace(
array_keys($map),
array_values($map),
$string
);
}

/**
* @param $widget
* @param $name
* @return bool
*/
private function isTextType($widget, $name)
{
$parameters = $widget->getParameters();

if (isset($parameters[$name]) && is_object($parameters[$name])) {
$type = $parameters[$name]->getType();
if ($type == 'text') {
return true;
}
}

return false;
}
}

0 comments on commit 7f0f260

Please sign in to comment.