Skip to content

Commit c6cc981

Browse files
author
Stanislav Idolov
committed
ENGCOM-2152: [Forwardport] Move breadcrumb json configuration to viewmodel #16466
1 parent 0c3e7f2 commit c6cc981

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\DataObject;
1414
use Magento\Framework\Serialize\Serializer\Json;
1515
use Magento\Framework\View\Element\Block\ArgumentInterface;
16+
use Magento\Framework\Escaper;
1617

1718
/**
1819
* Product breadcrumbs view model.
@@ -36,21 +37,29 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
3637
*/
3738
private $json;
3839

40+
/**
41+
* @var Escaper
42+
*/
43+
private $escaper;
44+
3945
/**
4046
* @param Data $catalogData
4147
* @param ScopeConfigInterface $scopeConfig
42-
* @param Json $json
48+
* @param Json|null $json
49+
* @param Escaper|null $escaper
4350
*/
4451
public function __construct(
4552
Data $catalogData,
4653
ScopeConfigInterface $scopeConfig,
47-
Json $json = null
54+
Json $json = null,
55+
Escaper $escaper = null
4856
) {
4957
parent::__construct();
5058

5159
$this->catalogData = $catalogData;
5260
$this->scopeConfig = $scopeConfig;
5361
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
62+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
5463
}
5564

5665
/**
@@ -98,12 +107,14 @@ public function getProductName(): string
98107
*/
99108
public function getJsonConfiguration()
100109
{
101-
return $this->json->serialize([
102-
'breadcrumbs' => [
103-
'categoryUrlSuffix' => $this->getCategoryUrlSuffix(),
104-
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
105-
'product' => $this->getProductName()
110+
return $this->json->serialize(
111+
[
112+
'breadcrumbs' => [
113+
'categoryUrlSuffix' => $this->escaper->escapeHtml($this->getCategoryUrlSuffix()),
114+
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
115+
'product' => $this->escaper->escapeHtml($this->escaper->escapeJs($this->getProductName()))
116+
]
106117
]
107-
]);
118+
);
108119
}
109120
}

0 commit comments

Comments
 (0)