Skip to content

Commit

Permalink
fix sitemap link renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigowebjump committed Apr 2, 2017
1 parent d570fcd commit b97281b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace Magento\Sitemap\Block\Adminhtml\Grid\Renderer;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
use Magento\Framework\App\ObjectManager;

class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
Expand All @@ -24,6 +26,11 @@ class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe
*/
protected $_sitemapFactory;

/**
* @var \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot
*/
protected $documentRoot;

/**
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Sitemap\Model\SitemapFactory $sitemapFactory
Expand All @@ -34,10 +41,13 @@ public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Sitemap\Model\SitemapFactory $sitemapFactory,
\Magento\Framework\Filesystem $filesystem,
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null,
array $data = []
) {
$this->_sitemapFactory = $sitemapFactory;
$this->_filesystem = $filesystem;
$this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);

parent::__construct($context, $data);
}

Expand All @@ -54,7 +64,8 @@ public function render(\Magento\Framework\DataObject $row)
$url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));

$fileName = preg_replace('/^\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::ROOT);
$documentRootPath = $this->documentRoot->getPath();
$directory = $this->_filesystem->getDirectoryRead($documentRootPath);
if ($directory->isFile($fileName)) {
return sprintf('<a href="%1$s">%1$s</a>', $url);
}
Expand Down

0 comments on commit b97281b

Please sign in to comment.