-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Sitemap class override, added plugin instead
- Loading branch information
1 parent
f423b0b
commit 8b2fda4
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved. | ||
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). | ||
* | ||
* Glory to Ukraine! Glory to the heroes! | ||
*/ | ||
|
||
namespace Magefan\Blog\Plugin\Magento\Sitemap; | ||
|
||
/** | ||
* Plugin for sitemap generation | ||
*/ | ||
class SitemapPlugin | ||
{ | ||
/** | ||
* @var \Magefan\Blog\Model\SitemapFactory | ||
*/ | ||
protected $sitemapFactory; | ||
|
||
/** | ||
* Generated sitemaps | ||
* @var array | ||
*/ | ||
protected $generated = []; | ||
|
||
public function __construct( | ||
\Magefan\Blog\Model\SitemapFactory $sitemapFactory | ||
) { | ||
$this->sitemapFactory = $sitemapFactory; | ||
} | ||
|
||
/** | ||
* Add magefan blog actions to allowed list | ||
* @param \Magento\Sitemap\Model\Sitemap $sitemap | ||
* @return array | ||
*/ | ||
public function afterGenerateXml(\Magento\Sitemap\Model\Sitemap $sitemap, $result) | ||
{ | ||
$sitemapId = $sitemap->getId() ?: 0; | ||
if (in_array($sitemapId, $this->generated)) { | ||
return $result; | ||
} | ||
$this->generated[] = $sitemapId; | ||
|
||
$blogSitemap = $this->sitemapFactory->create(); | ||
$blogSitemap->setData( | ||
$sitemap->getData() | ||
); | ||
|
||
$blogSitemap->setSitemapFilename( | ||
'blog_' . $sitemap->getSitemapFilename() | ||
); | ||
|
||
$blogSitemap->generateXml(); | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 8b2fda4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo. Also better use
return $this
when returns same instance.