Skip to content

Commit

Permalink
ENGCOM-4584: Fix broken widget placeholders after upgrading from 2.2 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Apr 5, 2019
2 parents 7198662 + 779200e commit d831f53
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
16 changes: 5 additions & 11 deletions app/code/Magento/Widget/Model/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,13 @@ public function getWidgets($filters = [])
$result = $widgets;

// filter widgets by params
if (is_array($filters) && count($filters) > 0) {
if (is_array($filters) && !empty($filters)) {
foreach ($widgets as $code => $widget) {
try {
foreach ($filters as $field => $value) {
if (!isset($widget[$field]) || (string)$widget[$field] != $value) {
throw new \Exception();
}
foreach ($filters as $field => $value) {
if (!isset($widget[$field]) || (string)$widget[$field] != $value) {
unset($result[$code]);
break;
}
} catch (\Exception $e) {
unset($result[$code]);
continue;
}
}
}
Expand Down Expand Up @@ -323,8 +319,6 @@ public function getWidgetDeclaration($type, $params = [], $asIs = true)

$directive .= $this->getWidgetPageVarName($params);

$directive .= sprintf(' type_name="%s"', $widget['name']);

$directive .= '}}';

if ($asIs) {
Expand Down
8 changes: 6 additions & 2 deletions app/code/Magento/Widget/Model/Widget/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function getWidgetPlaceholderImageUrls()

/**
* Return url to error image
*
* @return string
*/
public function getErrorImageUrl()
Expand All @@ -129,6 +130,7 @@ public function getErrorImageUrl()

/**
* Return url to wysiwyg plugin
*
* @return string
*/
public function getWysiwygJsPluginSrc()
Expand Down Expand Up @@ -157,7 +159,7 @@ public function getWidgetWindowUrl($config)
}
}

if (count($skipped) > 0) {
if (!empty($skipped)) {
$params['skip_widgets'] = $this->encodeWidgetsToQuery($skipped);
}
return $this->_backendUrl->getUrl('adminhtml/widget/index', $params);
Expand Down Expand Up @@ -189,6 +191,8 @@ public function decodeWidgetsFromQuery($queryParam)
}

/**
* Get available widgets.
*
* @param \Magento\Framework\DataObject $config Editor element config
* @return array
*/
Expand All @@ -202,7 +206,7 @@ public function getAvailableWidgets($config)
if (is_array($skipped) && in_array($widget['type'], $skipped)) {
continue;
}
$result[] = $widget['name']->getText();
$result[$widget['type']] = $widget['name']->getText();
}
}

Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Widget/Test/Unit/Model/WidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public function testGetWidgetDeclaration()
$this->assertContains('title="my "widget""', $result);
$this->assertContains('conditions_encoded="encoded-conditions-string"', $result);
$this->assertContains('page_var_name="pasdf"', $result);
$this->assertContains('type_name=""}}', $result);
}

/**
Expand Down Expand Up @@ -275,7 +274,6 @@ public function testGetWidgetDeclarationWithZeroValueParam()
);
$this->assertContains('{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"', $result);
$this->assertContains('page_var_name="pasdf"', $result);
$this->assertContains('type_name=""}}', $result);
$this->assertContains('products_count=""', $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ define([
attributes.type = attributes.type.replace(/\\\\/g, '\\');
imageSrc = config.placeholders[attributes.type];

if (config.types.indexOf(attributes['type_name']) > -1) {
if (imageSrc) {
imageHtml += '<span class="magento-placeholder magento-widget mceNonEditable" ' +
'contenteditable="false">';
} else {
Expand All @@ -147,8 +147,8 @@ define([
imageHtml += ' src="' + imageSrc + '"';
imageHtml += ' />';

if (attributes['type_name']) {
imageHtml += attributes['type_name'];
if (config.types[attributes.type]) {
imageHtml += config.types[attributes.type];
}

imageHtml += '</span>';
Expand Down

0 comments on commit d831f53

Please sign in to comment.