Contents.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
  8. class Contents extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
  9. {
  10. /**
  11. * @var \Magento\Framework\View\Result\LayoutFactory
  12. */
  13. protected $resultLayoutFactory;
  14. /**
  15. * @var \Magento\Framework\Controller\Result\JsonFactory
  16. */
  17. protected $resultJsonFactory;
  18. /**
  19. * @param \Magento\Backend\App\Action\Context $context
  20. * @param \Magento\Framework\Registry $coreRegistry
  21. * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
  22. * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  23. */
  24. public function __construct(
  25. \Magento\Backend\App\Action\Context $context,
  26. \Magento\Framework\Registry $coreRegistry,
  27. \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
  28. \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  29. ) {
  30. $this->resultLayoutFactory = $resultLayoutFactory;
  31. $this->resultJsonFactory = $resultJsonFactory;
  32. parent::__construct($context, $coreRegistry);
  33. }
  34. /**
  35. * Save current path in session
  36. *
  37. * @return $this
  38. */
  39. protected function _saveSessionCurrentPath()
  40. {
  41. $this->getStorage()->getSession()->setCurrentPath(
  42. $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class)->getCurrentPath()
  43. );
  44. return $this;
  45. }
  46. /**
  47. * Contents action
  48. *
  49. * @return \Magento\Framework\Controller\ResultInterface
  50. */
  51. public function execute()
  52. {
  53. try {
  54. $this->_initAction()->_saveSessionCurrentPath();
  55. /** @var \Magento\Framework\View\Result\Layout $resultLayout */
  56. $resultLayout = $this->resultLayoutFactory->create();
  57. return $resultLayout;
  58. } catch (\Exception $e) {
  59. $result = ['error' => true, 'message' => $e->getMessage()];
  60. /** @var \Magento\Framework\Controller\Result\Json $resultJson */
  61. $resultJson = $this->resultJsonFactory->create();
  62. $resultJson->setData($result);
  63. return $resultJson;
  64. }
  65. }
  66. }