resultRawFactory = $resultRawFactory; $this->resultJsonFactory = $resultJsonFactory; $this->directoryResolver = $directoryResolver ?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class); } /** * Delete folder action. * * @return \Magento\Framework\Controller\ResultInterface * @throws \Magento\Framework\Exception\LocalizedException */ public function execute() { try { $path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath(); if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) { throw new \Magento\Framework\Exception\LocalizedException( __('Directory %1 is not under storage root path.', $path) ); } $this->getStorage()->deleteDirectory($path); return $this->resultRawFactory->create(); } catch (\Exception $e) { $result = ['error' => true, 'message' => $e->getMessage()]; /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($result); } } }