Skip to content

Commit d67374f

Browse files
committed
Code refactor in Catalog Viewmodel breadcrumbs
1 parent 3a2561d commit d67374f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\DataObject;
13-
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\Framework\Serialize\Serializer\JsonHexTag;
1414
use Magento\Framework\View\Element\Block\ArgumentInterface;
1515
use Magento\Framework\Escaper;
1616

@@ -31,6 +31,11 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
3131
*/
3232
private $scopeConfig;
3333

34+
/**
35+
* @var JsonHexTag
36+
*/
37+
private $jsonSerializer;
38+
3439
/**
3540
* @var Escaper
3641
*/
@@ -39,20 +44,21 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
3944
/**
4045
* @param Data $catalogData
4146
* @param ScopeConfigInterface $scopeConfig
42-
* @param Json|null $json
47+
* @param JsonHexTag $jsonSerializer
4348
* @param Escaper|null $escaper
4449
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4550
*/
4651
public function __construct(
4752
Data $catalogData,
4853
ScopeConfigInterface $scopeConfig,
49-
Json $json = null,
54+
JsonHexTag $jsonSerializer,
5055
Escaper $escaper = null
5156
) {
5257
parent::__construct();
5358

5459
$this->catalogData = $catalogData;
5560
$this->scopeConfig = $scopeConfig;
61+
$this->jsonSerializer = $jsonSerializer;
5662
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
5763
}
5864

@@ -101,15 +107,14 @@ public function getProductName(): string
101107
*/
102108
public function getJsonConfigurationHtmlEscaped() : string
103109
{
104-
return json_encode(
110+
return $this->jsonSerializer->serialize(
105111
[
106112
'breadcrumbs' => [
107113
'categoryUrlSuffix' => $this->escaper->escapeHtml($this->getCategoryUrlSuffix()),
108114
'useCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
109115
'product' => $this->escaper->escapeHtml($this->getProductName())
110116
]
111-
],
112-
JSON_HEX_TAG
117+
]
113118
);
114119
}
115120

0 commit comments

Comments
 (0)