Breadcrumbs.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Catalog breadcrumbs
  8. */
  9. namespace Magento\Catalog\Block;
  10. use Magento\Catalog\Helper\Data;
  11. use Magento\Framework\View\Element\Template\Context;
  12. use Magento\Store\Model\Store;
  13. class Breadcrumbs extends \Magento\Framework\View\Element\Template
  14. {
  15. /**
  16. * Catalog data
  17. *
  18. * @var Data
  19. */
  20. protected $_catalogData = null;
  21. /**
  22. * @param Context $context
  23. * @param Data $catalogData
  24. * @param array $data
  25. */
  26. public function __construct(Context $context, Data $catalogData, array $data = [])
  27. {
  28. $this->_catalogData = $catalogData;
  29. parent::__construct($context, $data);
  30. }
  31. /**
  32. * Retrieve HTML title value separator (with space)
  33. *
  34. * @param null|string|bool|int|Store $store
  35. * @return string
  36. */
  37. public function getTitleSeparator($store = null)
  38. {
  39. $separator = (string)$this->_scopeConfig->getValue(
  40. 'catalog/seo/title_separator',
  41. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  42. $store
  43. );
  44. return ' ' . $separator . ' ';
  45. }
  46. /**
  47. * Preparing layout
  48. *
  49. * @return \Magento\Catalog\Block\Breadcrumbs
  50. */
  51. protected function _prepareLayout()
  52. {
  53. if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
  54. $breadcrumbsBlock->addCrumb(
  55. 'home',
  56. [
  57. 'label' => __('Home'),
  58. 'title' => __('Go to Home Page'),
  59. 'link' => $this->_storeManager->getStore()->getBaseUrl()
  60. ]
  61. );
  62. $title = [];
  63. $path = $this->_catalogData->getBreadcrumbPath();
  64. foreach ($path as $name => $breadcrumb) {
  65. $breadcrumbsBlock->addCrumb($name, $breadcrumb);
  66. $title[] = $breadcrumb['label'];
  67. }
  68. $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
  69. }
  70. return parent::_prepareLayout();
  71. }
  72. }