/** * Return tree node full path based on current path * * @return string */ public function getTreeCurrentPath() { $treePath = array('root'); if ($path = $this->_coreRegistry->registry('storage')->getSession()->getCurrentPath()) { $path = str_replace($this->_cmsWysiwygImages->getStorageRoot(), '', $path); $relative = array(); foreach (explode('/', $path) as $dirName) { if ($dirName) { $relative[] = $dirName; $treePath[] = $this->_cmsWysiwygImages->idEncode(implode('/', $relative)); } } } return $treePath; }
/** * Return files * * @param string $path Parent directory path * @param string $type Type of storage, e.g. image, media etc. * @return \Magento\Framework\Data\Collection\Filesystem */ public function getFilesCollection($path, $type = null) { if ($this->_coreFileStorageDb->checkDbUsage()) { $files = $this->_storageDatabaseFactory->create()->getDirectoryFiles($path); /** @var \Magento\MediaStorage\Model\File\Storage\File $fileStorageModel */ $fileStorageModel = $this->_storageFileFactory->create(); foreach ($files as $file) { $fileStorageModel->saveFile($file); } } $collection = $this->getCollection($path)->setCollectDirs(false)->setCollectFiles(true)->setCollectRecursively(false)->setOrder('mtime', \Magento\Framework\Data\Collection::SORT_ORDER_ASC); // Add files extension filter if ($allowed = $this->getAllowedExtensions($type)) { $collection->setFilesFilter('/\\.(' . implode('|', $allowed) . ')$/i'); } // prepare items foreach ($collection as $item) { $item->setId($this->_cmsWysiwygImages->idEncode($item->getBasename())); $item->setName($item->getBasename()); $item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename())); $item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename()); if ($this->isImage($item->getBasename())) { $thumbUrl = $this->getThumbnailUrl($item->getFilename(), true); // generate thumbnail "on the fly" if it does not exists if (!$thumbUrl) { $thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]); } $size = @getimagesize($item->getFilename()); if (is_array($size)) { $item->setWidth($size[0]); $item->setHeight($size[1]); } } else { $thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX); } $item->setThumbUrl($thumbUrl); } return $collection; }