Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Link.php
Go to the documentation of this file.
1 <?php
12 
16 
17 class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
18 {
22  protected $_filesystem;
23 
27  protected $_sitemapFactory;
28 
32  protected $documentRoot;
33 
41  public function __construct(
42  \Magento\Backend\Block\Context $context,
43  \Magento\Sitemap\Model\SitemapFactory $sitemapFactory,
44  \Magento\Framework\Filesystem $filesystem,
45  array $data = [],
47  ) {
48  $this->_sitemapFactory = $sitemapFactory;
49  $this->_filesystem = $filesystem;
50  $this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
51 
52  parent::__construct($context, $data);
53  }
54 
61  public function render(\Magento\Framework\DataObject $row)
62  {
64  $sitemap = $this->_sitemapFactory->create();
65  $url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));
66 
67  $fileName = preg_replace('/^\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
68  $documentRootPath = $this->documentRoot->getPath();
69  $directory = $this->_filesystem->getDirectoryRead($documentRootPath);
70  if ($directory->isFile($fileName)) {
71  return sprintf('<a href="%1$s">%1$s</a>', $url);
72  }
73 
74  return $url;
75  }
76 }
$fileName
Definition: translate.phtml:15
$filesystem