Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Breadcrumbs.php
Go to the documentation of this file.
1 <?php
8 
16 
20 class Breadcrumbs extends DataObject implements ArgumentInterface
21 {
27  private $catalogData;
28 
32  private $scopeConfig;
33 
37  private $escaper;
38 
46  public function __construct(
47  Data $catalogData,
48  ScopeConfigInterface $scopeConfig,
49  Json $json = null,
50  Escaper $escaper = null
51  ) {
52  parent::__construct();
53 
54  $this->catalogData = $catalogData;
55  $this->scopeConfig = $scopeConfig;
56  $this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
57  }
58 
64  public function getCategoryUrlSuffix()
65  {
66  return $this->scopeConfig->getValue(
67  'catalog/seo/category_url_suffix',
68  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
69  );
70  }
71 
77  public function isCategoryUsedInProductUrl(): bool
78  {
79  return $this->scopeConfig->isSetFlag(
80  'catalog/seo/product_use_categories',
81  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
82  );
83  }
84 
90  public function getProductName(): string
91  {
92  return $this->catalogData->getProduct() !== null
93  ? $this->catalogData->getProduct()->getName()
94  : '';
95  }
96 
102  public function getJsonConfigurationHtmlEscaped() : string
103  {
104  return json_encode(
105  [
106  'breadcrumbs' => [
107  'categoryUrlSuffix' => $this->escaper->escapeHtml($this->getCategoryUrlSuffix()),
108  'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
109  'product' => $this->escaper->escapeHtml($this->getProductName())
110  ]
111  ],
112  JSON_HEX_TAG
113  );
114  }
115 
122  public function getJsonConfiguration()
123  {
124  return $this->getJsonConfigurationHtmlEscaped();
125  }
126 }
__construct(Data $catalogData, ScopeConfigInterface $scopeConfig, Json $json=null, Escaper $escaper=null)
Definition: Breadcrumbs.php:46