File tree Expand file tree Collapse file tree 2 files changed +36
-15
lines changed
Expand file tree Collapse file tree 2 files changed +36
-15
lines changed Original file line number Diff line number Diff line change 66
77namespace Magefan \HtmlSitemap \Block ;
88
9+ use Magefan \HtmlSitemap \Model \Config ;
10+
911class Link extends \Magento \Framework \View \Element \Html \Link
1012{
1113 /**
1214 * @var \Magefan\HtmlSitemap\Model\Url
1315 */
1416 protected $ _url ;
1517
18+ /**
19+ * @var Config
20+ */
21+ private Config $ config ;
22+
1623 /**
1724 * @param \Magento\Framework\View\Element\Template\Context $context
18- * @param \Magefan\HtmlSitemap\Model\Url $url
25+ * @param \Magento\Framework\UrlInterface $url
26+ * @param Config $config
1927 * @param array $data
2028 */
2129 public function __construct (
2230 \Magento \Framework \View \Element \Template \Context $ context ,
2331 \Magento \Framework \UrlInterface $ url ,
32+ Config $ config ,
2433 array $ data = []
2534 ) {
2635 $ this ->_url = $ url ;
36+ $ this ->config = $ config ;
2737 parent ::__construct ($ context , $ data );
2838 }
2939
@@ -72,4 +82,20 @@ protected function _toHtml()
7282 }
7383 return parent ::_toHtml ();
7484 }
85+
86+ /**
87+ * @return bool
88+ */
89+ public function canShowSitemapLink (): bool
90+ {
91+ return in_array ('1 ' , $ this ->getDisplayIn ());
92+ }
93+
94+ /**
95+ * @return array
96+ */
97+ private function getDisplayIn (): array
98+ {
99+ return explode (', ' , $ this ->config ->displayIn ());
100+ }
75101}
Original file line number Diff line number Diff line change 44 * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
55 */
66
7- /**
8- * @var $block \Magefan\HtmlSitemap\Block\Link
9- */
10- ?>
7+ use Magefan \HtmlSitemap \Block \Link ;
8+ use Magento \Framework \Escaper ;
119
12- <?php
13- $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
14- $ config = $ objectManager ->create (\Magefan \HtmlSitemap \Model \Config::class);
15- $ displayInArray = explode (', ' , $ config ->displayIn ());
16- $ openLinks = ($ block ->getOpenLinks () == 1 ) ? '' : 'target="_blank" ' ;
10+ /** @var Link $block */
11+ /** @var Escaper $escaper */
12+
13+ $ openLinks = $ block ->getOpenLinks () == 1 ? '' : 'target="_blank" ' ;
1714?>
18- <?php if ($ config ->isEnabled ()): ?>
19- <?php if (in_array ('1 ' , $ displayInArray )): ?>
15+ <?php if ($ block ->canShowSitemapLink ()): ?>
2016 <li>
21- <a href="<?= $ block ->escapeUrl ($ block ->getHref ()) ?> " name="header_htmlsitemap_link" <?= $ openLinks ?> >
22- <?= $ block ->escapeHtml ($ block ->getLabel ()) ?>
17+ <a href="<?= $ escaper ->escapeUrl ($ block ->getHref ()) ?> " name="header_htmlsitemap_link" <?= $ openLinks ?> >
18+ <?= $ escaper ->escapeHtml ($ block ->getLabel ()) ?>
2319 </a>
2420 </li>
25- <?php endif ?>
2621<?php endif ?>
You can’t perform that action at this time.
0 commit comments