Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Tree.php
Go to the documentation of this file.
1 <?php
7 
16 {
20  protected $_storageHelper;
21 
25  protected $urlEncoder;
26 
30  private $serializer;
31 
40  public function __construct(
41  \Magento\Backend\Block\Template\Context $context,
42  \Magento\Theme\Helper\Storage $storageHelper,
43  \Magento\Framework\Url\EncoderInterface $urlEncoder,
44  array $data = [],
45  \Magento\Framework\Serialize\Serializer\Json $serializer = null
46  ) {
47  $this->_storageHelper = $storageHelper;
48  $this->urlEncoder = $urlEncoder;
49  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
50  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
51  parent::__construct($context, $data);
52  }
53 
59  public function getTreeLoaderUrl()
60  {
61  return $this->getUrl('adminhtml/*/treeJson', $this->_storageHelper->getRequestParams());
62  }
63 
70  public function getTreeJson($data)
71  {
72  return $this->serializer->serialize($data);
73  }
74 
80  public function getRootNodeName()
81  {
82  return __('Storage Root');
83  }
84 
90  public function getTreeCurrentPath()
91  {
92  $treePath = '/root';
93  $path = $this->_storageHelper->getSession()->getCurrentPath();
94  if ($path) {
95  $path = str_replace($this->_storageHelper->getStorageRoot(), '', $path);
96  $relative = '';
97  foreach (explode('/', $path) as $dirName) {
98  if ($dirName) {
99  $relative .= '/' . $dirName;
100  $treePath .= '/' . $this->urlEncoder->encode($relative);
101  }
102  }
103  }
104  return $treePath;
105  }
106 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Theme\Helper\Storage $storageHelper, \Magento\Framework\Url\EncoderInterface $urlEncoder, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
Definition: Tree.php:40
__()
Definition: __.php:13