From b7e01988f02d9a81a9811745479da58d21367db9 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Fri, 7 Aug 2020 10:26:23 +0100 Subject: [PATCH 1/3] Fixed issue where removing breadcrumbs removes the page title --- .../Magento/Catalog/Block/Breadcrumbs.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Breadcrumbs.php b/app/code/Magento/Catalog/Block/Breadcrumbs.php index 674c99001b01a..f2bbcf4d26aab 100644 --- a/app/code/Magento/Catalog/Block/Breadcrumbs.php +++ b/app/code/Magento/Catalog/Block/Breadcrumbs.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. */ +// @codingStandardsIgnoreFile + /** * Catalog breadcrumbs */ @@ -41,11 +43,7 @@ public function __construct(Context $context, Data $catalogData, array $data = [ */ public function getTitleSeparator($store = null) { - $separator = (string)$this->_scopeConfig->getValue( - 'catalog/seo/title_separator', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $store - ); + $separator = (string)$this->_scopeConfig->getValue('catalog/seo/title_separator', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); return ' ' . $separator . ' '; } @@ -56,6 +54,7 @@ public function getTitleSeparator($store = null) */ protected function _prepareLayout() { + $title = []; if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) { $breadcrumbsBlock->addCrumb( 'home', @@ -66,7 +65,6 @@ protected function _prepareLayout() ] ); - $title = []; $path = $this->_catalogData->getBreadcrumbPath(); foreach ($path as $name => $breadcrumb) { @@ -75,7 +73,18 @@ protected function _prepareLayout() } $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title))); + + return parent::_prepareLayout(); } + + $path = $this->_catalogData->getBreadcrumbPath(); + + foreach ($path as $name => $breadcrumb) { + $title[] = $breadcrumb['label']; + } + + $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title))); + return parent::_prepareLayout(); } } From 1cc621c7b34c43a7ffa5b66ad67d2a981d6254ee Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Mon, 2 Nov 2020 13:27:25 +0000 Subject: [PATCH 2/3] Streamlining the _prepareLayout() method --- .../Magento/Catalog/Block/Breadcrumbs.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Breadcrumbs.php b/app/code/Magento/Catalog/Block/Breadcrumbs.php index f2bbcf4d26aab..b8ed8234cf7dd 100644 --- a/app/code/Magento/Catalog/Block/Breadcrumbs.php +++ b/app/code/Magento/Catalog/Block/Breadcrumbs.php @@ -54,7 +54,8 @@ public function getTitleSeparator($store = null) */ protected function _prepareLayout() { - $title = []; + $path = $this->_catalogData->getBreadcrumbPath(); + if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) { $breadcrumbsBlock->addCrumb( 'home', @@ -64,27 +65,13 @@ protected function _prepareLayout() 'link' => $this->_storeManager->getStore()->getBaseUrl() ] ); - - $path = $this->_catalogData->getBreadcrumbPath(); - foreach ($path as $name => $breadcrumb) { $breadcrumbsBlock->addCrumb($name, $breadcrumb); - $title[] = $breadcrumb['label']; } - - $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title))); - - return parent::_prepareLayout(); - } - - $path = $this->_catalogData->getBreadcrumbPath(); - - foreach ($path as $name => $breadcrumb) { - $title[] = $breadcrumb['label']; } + $title = array_column($path, 'label'); $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title))); - return parent::_prepareLayout(); } } From a46e34a1a625dcc5550c69e1b00bc4d6f6da6a29 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 10 Nov 2020 14:27:54 +0000 Subject: [PATCH 3/3] Bringing Breadcrumbs.php in line with PSR Magento standards --- app/code/Magento/Catalog/Block/Breadcrumbs.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Breadcrumbs.php b/app/code/Magento/Catalog/Block/Breadcrumbs.php index b8ed8234cf7dd..ba5c33963586f 100644 --- a/app/code/Magento/Catalog/Block/Breadcrumbs.php +++ b/app/code/Magento/Catalog/Block/Breadcrumbs.php @@ -4,8 +4,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - /** * Catalog breadcrumbs */ @@ -43,7 +41,11 @@ public function __construct(Context $context, Data $catalogData, array $data = [ */ public function getTitleSeparator($store = null) { - $separator = (string)$this->_scopeConfig->getValue('catalog/seo/title_separator', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); + $separator = (string)$this->_scopeConfig->getValue( + 'catalog/seo/title_separator', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $store + ); return ' ' . $separator . ' '; }