1111use Magento \Robots \Model \Config \Value ;
1212use Magento \Sitemap \Helper \Data as SitemapHelper ;
1313use Magento \Sitemap \Model \ResourceModel \Sitemap \CollectionFactory ;
14+ use Magento \Sitemap \Model \SitemapConfigReader ;
15+ use Magento \Framework \App \ObjectManager ;
1416use Magento \Store \Model \StoreManagerInterface ;
1517use Magento \Store \Model \StoreResolver ;
1618
@@ -29,6 +31,7 @@ class Robots extends AbstractBlock implements IdentityInterface
2931
3032 /**
3133 * @var SitemapHelper
34+ * @deprecated
3235 */
3336 private $ sitemapHelper ;
3437
@@ -37,14 +40,19 @@ class Robots extends AbstractBlock implements IdentityInterface
3740 */
3841 private $ storeManager ;
3942
43+ /**
44+ * @var SitemapConfigReader
45+ */
46+ private $ sitemapConfigReader ;
47+
4048 /**
4149 * @param Context $context
4250 * @param StoreResolver $storeResolver
4351 * @param CollectionFactory $sitemapCollectionFactory
4452 * @param SitemapHelper $sitemapHelper
4553 * @param StoreManagerInterface $storeManager
4654 * @param array $data
47- *
55+ * @param SitemapConfigReader|null $sitemapConfigReader
4856 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
4957 */
5058 public function __construct (
@@ -53,11 +61,14 @@ public function __construct(
5361 CollectionFactory $ sitemapCollectionFactory ,
5462 SitemapHelper $ sitemapHelper ,
5563 StoreManagerInterface $ storeManager ,
56- array $ data = []
64+ array $ data = [],
65+ ?SitemapConfigReader $ sitemapConfigReader = null
5766 ) {
5867 $ this ->sitemapCollectionFactory = $ sitemapCollectionFactory ;
5968 $ this ->sitemapHelper = $ sitemapHelper ;
6069 $ this ->storeManager = $ storeManager ;
70+ $ this ->sitemapConfigReader = $ sitemapConfigReader
71+ ?: ObjectManager::getInstance ()->get (SitemapConfigReader::class);
6172
6273 parent ::__construct ($ context , $ data );
6374 }
@@ -74,22 +85,16 @@ public function __construct(
7485 */
7586 protected function _toHtml ()
7687 {
77- $ defaultStore = $ this ->storeManager ->getDefaultStoreView ();
78-
79- /** @var \Magento\Store\Model\Website $website */
80- $ website = $ this ->storeManager ->getWebsite ($ defaultStore ->getWebsiteId ());
88+ $ website = $ this ->storeManager ->getWebsite ();
8189
8290 $ storeIds = [];
8391 foreach ($ website ->getStoreIds () as $ storeId ) {
84- if ((bool )$ this ->sitemapHelper ->getEnableSubmissionRobots ($ storeId )) {
85- $ storeIds [] = (int )$ storeId ;
92+ if ((bool ) $ this ->sitemapConfigReader ->getEnableSubmissionRobots ($ storeId )) {
93+ $ storeIds [] = (int ) $ storeId ;
8694 }
8795 }
8896
89- $ links = [];
90- if ($ storeIds ) {
91- $ links = array_merge ($ links , $ this ->getSitemapLinks ($ storeIds ));
92- }
97+ $ links = $ storeIds ? $ this ->getSitemapLinks ($ storeIds ) : [];
9398
9499 return $ links ? implode (PHP_EOL , $ links ) . PHP_EOL : '' ;
95100 }
@@ -106,18 +111,12 @@ protected function _toHtml()
106111 */
107112 protected function getSitemapLinks (array $ storeIds )
108113 {
109- $ sitemapLinks = [];
110-
111- /** @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection $collection */
112114 $ collection = $ this ->sitemapCollectionFactory ->create ();
113115 $ collection ->addStoreFilter ($ storeIds );
114116
117+ $ sitemapLinks = [];
115118 foreach ($ collection as $ sitemap ) {
116- /** @var \Magento\Sitemap\Model\Sitemap $sitemap */
117- $ sitemapFilename = $ sitemap ->getSitemapFilename ();
118- $ sitemapPath = $ sitemap ->getSitemapPath ();
119-
120- $ sitemapUrl = $ sitemap ->getSitemapUrl ($ sitemapPath , $ sitemapFilename );
119+ $ sitemapUrl = $ sitemap ->getSitemapUrl ($ sitemap ->getSitemapPath (), $ sitemap ->getSitemapFilename ());
121120 $ sitemapLinks [$ sitemapUrl ] = 'Sitemap: ' . $ sitemapUrl ;
122121 }
123122
0 commit comments