Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OnInsert.php
Go to the documentation of this file.
1 <?php
8 
10 {
14  protected $resultRawFactory;
15 
21  public function __construct(
22  \Magento\Backend\App\Action\Context $context,
23  \Magento\Framework\Registry $coreRegistry,
24  \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
25  ) {
26  $this->resultRawFactory = $resultRawFactory;
27  parent::__construct($context, $coreRegistry);
28  }
29 
35  public function execute()
36  {
37  $imagesHelper = $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
38  $request = $this->getRequest();
39 
40  $storeId = $request->getParam('store');
41 
42  $filename = $request->getParam('filename');
43  $filename = $imagesHelper->idDecode($filename);
44 
45  $asIs = $request->getParam('as_is');
46 
47  $forceStaticPath = $request->getParam('force_static_path');
48 
49  $this->_objectManager->get(\Magento\Catalog\Helper\Data::class)->setStoreId($storeId);
50  $imagesHelper->setStoreId($storeId);
51 
52  if ($forceStaticPath) {
53  $image = parse_url($imagesHelper->getCurrentUrl() . $filename, PHP_URL_PATH);
54  } else {
55  $image = $imagesHelper->getImageHtmlDeclaration($filename, $asIs);
56  }
57 
59  $resultRaw = $this->resultRawFactory->create();
60  return $resultRaw->setContents($image);
61  }
62 }
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory)
Definition: OnInsert.php:21