Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Directive.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
13 
19  const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
20 
24  protected $urlDecoder;
25 
29  protected $resultRawFactory;
30 
36  public function __construct(
37  Action\Context $context,
38  \Magento\Framework\Url\DecoderInterface $urlDecoder,
39  \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
40  ) {
41  parent::__construct($context);
42  $this->urlDecoder = $urlDecoder;
43  $this->resultRawFactory = $resultRawFactory;
44  }
45 
51  public function execute()
52  {
53  $directive = $this->getRequest()->getParam('___directive');
54  $directive = $this->urlDecoder->decode($directive);
55  $imagePath = $this->_objectManager->create(\Magento\Cms\Model\Template\Filter::class)->filter($directive);
57  $image = $this->_objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
59  $resultRaw = $this->resultRawFactory->create();
60  try {
61  $image->open($imagePath);
62  $resultRaw->setHeader('Content-Type', $image->getMimeType());
63  $resultRaw->setContents($image->getImage());
64  } catch (\Exception $e) {
65  $imagePath = $this->_objectManager->get(
66  \Magento\Cms\Model\Wysiwyg\Config::class
67  )->getSkinImagePlaceholderPath();
68  $image->open($imagePath);
69  $resultRaw->setHeader('Content-Type', $image->getMimeType());
70  $resultRaw->setContents($image->getImage());
71  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
72  }
73  return $resultRaw;
74  }
75 }
__construct(Action\Context $context, \Magento\Framework\Url\DecoderInterface $urlDecoder, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory)
Definition: Directive.php:36