Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use Magento\Catalog\Helper\Data;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
Expand All @@ -27,18 +29,26 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
*/
private $scopeConfig;

/**
* @var Json
*/
private $json;

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

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

/**
Expand Down Expand Up @@ -78,4 +88,20 @@ public function getProductName()
? $this->catalogData->getProduct()->getName()
: '';
}

/**
* Returns breadcrumb json.
*
* @return string
*/
public function getJsonConfiguration()
{
return $this->json->serialize([
'breadcrumbs' => [
'categoryUrlSuffix' => $this->getCategoryUrlSuffix(),
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
'product' => $this->getProductName()
]
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@
/** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */
$viewModel = $block->getData('viewModel');
?>
<div class="breadcrumbs" data-mage-init='{
"breadcrumbs": {
"categoryUrlSuffix": "<?= $block->escapeHtml($viewModel->getCategoryUrlSuffix()); ?>",
"useCategoryPathInUrl": <?= (int)$viewModel->isCategoryUsedInProductUrl(); ?>,
"product": "<?= $block->escapeHtml($block->escapeJs($viewModel->getProductName())); ?>"
}
}'>
</div>
<div class="breadcrumbs" data-mage-init='<?= /* @escapeNotVerified */ $viewModel->getJsonConfiguration() ?>'></div>