123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- 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;
- /**
- * Sitemap grid link column renderer
- */
- class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
- {
- /**
- * @var \Magento\Framework\Filesystem $filesystem
- */
- protected $_filesystem;
- /**
- * @var \Magento\Sitemap\Model\SitemapFactory
- */
- protected $_sitemapFactory;
- /**
- * @var DocumentRoot
- */
- protected $documentRoot;
- /**
- * @param \Magento\Backend\Block\Context $context
- * @param \Magento\Sitemap\Model\SitemapFactory $sitemapFactory
- * @param \Magento\Framework\Filesystem $filesystem
- * @param array $data
- * @param DocumentRoot $documentRoot
- */
- public function __construct(
- \Magento\Backend\Block\Context $context,
- \Magento\Sitemap\Model\SitemapFactory $sitemapFactory,
- \Magento\Framework\Filesystem $filesystem,
- array $data = [],
- DocumentRoot $documentRoot = null
- ) {
- $this->_sitemapFactory = $sitemapFactory;
- $this->_filesystem = $filesystem;
- $this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
- parent::__construct($context, $data);
- }
- /**
- * Prepare link to display in grid
- *
- * @param \Magento\Framework\DataObject $row
- * @return string
- */
- public function render(\Magento\Framework\DataObject $row)
- {
- /** @var $sitemap \Magento\Sitemap\Model\Sitemap */
- $sitemap = $this->_sitemapFactory->create();
- $sitemap->setStoreId($row->getStoreId());
- $url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));
- $fileName = preg_replace('/^\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
- $documentRootPath = $this->documentRoot->getPath();
- $directory = $this->_filesystem->getDirectoryRead($documentRootPath);
- if ($directory->isFile($fileName)) {
- return sprintf('<a href="%1$s">%1$s</a>', $url);
- }
- return $url;
- }
- }
|