Skip to content

Commit

Permalink
ENGCOM-2152: [Forwardport] Move breadcrumb json configuration to view…
Browse files Browse the repository at this point in the history
…model #16466
  • Loading branch information
Stanislav Idolov committed Jul 4, 2018
1 parent 0c3e7f2 commit c6cc981
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\DataObject;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\Escaper;

/**
* Product breadcrumbs view model.
Expand All @@ -36,21 +37,29 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
*/
private $json;

/**
* @var Escaper
*/
private $escaper;

/**
* @param Data $catalogData
* @param ScopeConfigInterface $scopeConfig
* @param Json $json
* @param Json|null $json
* @param Escaper|null $escaper
*/
public function __construct(
Data $catalogData,
ScopeConfigInterface $scopeConfig,
Json $json = null
Json $json = null,
Escaper $escaper = null
) {
parent::__construct();

$this->catalogData = $catalogData;
$this->scopeConfig = $scopeConfig;
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
}

/**
Expand Down Expand Up @@ -98,12 +107,14 @@ public function getProductName(): string
*/
public function getJsonConfiguration()
{
return $this->json->serialize([
'breadcrumbs' => [
'categoryUrlSuffix' => $this->getCategoryUrlSuffix(),
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
'product' => $this->getProductName()
return $this->json->serialize(
[
'breadcrumbs' => [
'categoryUrlSuffix' => $this->escaper->escapeHtml($this->getCategoryUrlSuffix()),
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
'product' => $this->escaper->escapeHtml($this->escaper->escapeJs($this->getProductName()))
]
]
]);
);
}
}

0 comments on commit c6cc981

Please sign in to comment.