From 3a0383808ced01ac1d6af8d7df8fad334866b3d5 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 6 Feb 2019 09:44:37 +0200 Subject: [PATCH 1/5] Fixing the multidimensional array as value for the widget's parameter --- .../Magento/Widget/Block/Adminhtml/Widget/Options.php | 4 +++- .../Magento/Framework/Data/Form/Element/Label.php | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php index beac66dce5016..e8f4baf6e3d9f 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php @@ -165,7 +165,9 @@ protected function _addField($parameter) if (is_array($data['value'])) { foreach ($data['value'] as &$value) { - $value = html_entity_decode($value); + if (!is_array($value)) { + $value = html_entity_decode($value); + } } } else { $data['value'] = html_entity_decode($data['value']); diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Label.php b/lib/internal/Magento/Framework/Data/Form/Element/Label.php index 901dcb5289e8d..a95c7646eadce 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Label.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Label.php @@ -37,8 +37,14 @@ public function __construct( public function getElementHtml() { $html = $this->getBold() ? '
' : '
'; - $html .= $this->getEscapedValue() . '
'; + if (is_array($this->getValue())) { + $html .= '
'; + } else { + $html .= $this->getEscapedValue() . ''; + } + $html .= $this->getAfterElementHtml(); + return $html; } } From 4c84817c2a3c5b3b4985900e024437f03ab5704b Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 6 Feb 2019 12:31:31 +0200 Subject: [PATCH 2/5] Refactoring the if condition --- lib/internal/Magento/Framework/Data/Form/Element/Label.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Label.php b/lib/internal/Magento/Framework/Data/Form/Element/Label.php index a95c7646eadce..a2efb72c75542 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Label.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Label.php @@ -37,12 +37,11 @@ public function __construct( public function getElementHtml() { $html = $this->getBold() ? '
' : '
'; - if (is_array($this->getValue())) { - $html .= '
'; - } else { - $html .= $this->getEscapedValue() . '
'; + if (!is_array($this->getValue())) { + $html .= $this->getEscapedValue(); } + $html .= ''; $html .= $this->getAfterElementHtml(); return $html; From 640127d884e8bf47206cc919f2af34b766b1222d Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 7 Feb 2019 13:25:45 +0200 Subject: [PATCH 3/5] Applying some minor adjustments --- app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php | 2 +- lib/internal/Magento/Framework/Data/Form/Element/Label.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php index e8f4baf6e3d9f..20eaa61ca6dcf 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php @@ -165,7 +165,7 @@ protected function _addField($parameter) if (is_array($data['value'])) { foreach ($data['value'] as &$value) { - if (!is_array($value)) { + if (is_string($value)) { $value = html_entity_decode($value); } } diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Label.php b/lib/internal/Magento/Framework/Data/Form/Element/Label.php index a2efb72c75542..d9834b8c15ee1 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Label.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Label.php @@ -37,7 +37,7 @@ public function __construct( public function getElementHtml() { $html = $this->getBold() ? '
' : '
'; - if (!is_array($this->getValue())) { + if (is_string($this->getValue())) { $html .= $this->getEscapedValue(); } From 3a4150d0910f75cd884325cdbd13f1e731da47cb Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 2 Apr 2019 11:51:09 +0300 Subject: [PATCH 4/5] Fix functional and static tests. --- .../Widget/Block/Adminhtml/Widget/Options.php | 5 +++-- .../Magento/Framework/Data/Form/Element/Label.php | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php index 20eaa61ca6dcf..f7a2480a32b28 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php @@ -91,7 +91,7 @@ public function getMainFieldset() if ($this->_getData('main_fieldset') instanceof \Magento\Framework\Data\Form\Element\Fieldset) { return $this->_getData('main_fieldset'); } - $mainFieldsetHtmlId = 'options_fieldset' . md5($this->getWidgetType()); + $mainFieldsetHtmlId = 'options_fieldset' . hash('sha256', $this->getWidgetType()); $this->setMainFieldsetHtmlId($mainFieldsetHtmlId); $fieldset = $this->getForm()->addFieldset( $mainFieldsetHtmlId, @@ -141,7 +141,6 @@ protected function _addField($parameter) { $form = $this->getForm(); $fieldset = $this->getMainFieldset(); - //$form->getElement('options_fieldset'); // prepare element data with values (either from request of from default values) $fieldName = $parameter->getKey(); @@ -166,10 +165,12 @@ protected function _addField($parameter) if (is_array($data['value'])) { foreach ($data['value'] as &$value) { if (is_string($value)) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $value = html_entity_decode($value); } } } else { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $data['value'] = html_entity_decode($data['value']); } diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Label.php b/lib/internal/Magento/Framework/Data/Form/Element/Label.php index d9834b8c15ee1..70b7885e7a0d0 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Label.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Label.php @@ -4,13 +4,13 @@ * See COPYING.txt for license details. */ -/** - * Data form abstract class - * - * @author Magento Core Team - */ namespace Magento\Framework\Data\Form\Element; +use Magento\Framework\Phrase; + +/** + * Label form element. + */ class Label extends \Magento\Framework\Data\Form\Element\AbstractElement { /** @@ -37,7 +37,7 @@ public function __construct( public function getElementHtml() { $html = $this->getBold() ? '
' : '
'; - if (is_string($this->getValue())) { + if (is_string($this->getValue()) || $this->getValue() instanceof Phrase) { $html .= $this->getEscapedValue(); } From c365d6cb5def47773e9a06eebd196039b7b76d52 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Mon, 22 Apr 2019 17:41:07 +0300 Subject: [PATCH 5/5] Fix static test. --- app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php index f7a2480a32b28..c1182505bc0c6 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php @@ -158,7 +158,7 @@ protected function _addField($parameter) $data['value'] = $parameter->getValue(); //prepare unique id value if ($fieldName == 'unique_id' && $data['value'] == '') { - $data['value'] = md5(microtime(1)); + $data['value'] = hash('sha256', microtime(1)); } }