From 213e11d576d72a3d6bd2efd1a2f309f91d200d5d Mon Sep 17 00:00:00 2001 From: Diederick Bruin Date: Fri, 25 May 2018 16:07:53 +0200 Subject: [PATCH] Move breadcrumb json configuration to viewmodel --- .../Catalog/ViewModel/Product/Breadcrumbs.php | 27 ++++++++++++++++++- .../templates/product/breadcrumbs.phtml | 9 +------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php b/app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php index 2f2048b2a3013..213f2fc34f621 100644 --- a/app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php +++ b/app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php @@ -8,6 +8,7 @@ use Magento\Catalog\Helper\Data; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\View\Element\Block\ArgumentInterface; /** @@ -27,18 +28,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 ) { parent::__construct(); $this->catalogData = $catalogData; $this->scopeConfig = $scopeConfig; + $this->json = $json; } /** @@ -78,4 +87,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() + ] + ]); + } } diff --git a/app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml b/app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml index 063f8857329e5..d66aa5e5edb28 100644 --- a/app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml +++ b/app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml @@ -7,11 +7,4 @@ /** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */ $viewModel = $block->getData('viewModel'); ?> - +