layoutFactory = $layoutFactory; $this->resultJsonFactory = $resultJsonFactory; parent::__construct($context, $coreRegistry); } /** * Tree json action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); try { $this->_initAction(); /** @var \Magento\Framework\View\Layout $layout */ $layout = $this->layoutFactory->create(); $resultJson->setJsonData( $layout->createBlock( \Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Tree::class )->getTreeJson() ); } catch (\Exception $e) { $result = ['error' => true, 'message' => $e->getMessage()]; $resultJson->setData($result); } return $resultJson; } }