0

I want to put an around plugin.

This is the core file vendor/magento/module-cms/Controller/Adminhtml/Wysiwyg/Images/Thumbnail.php

The main purpose is on the execute function I want to upload a custom icon for WYSIWYG.

            $image = $this->_objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
            $image->open('media/wysiwyg/test_icon.png');
            $resultRaw->setHeader('Content-Type', $image->getMimeType());
            $resultRaw->setContents($image->getImage());

1 Answer 1

0

1.Create a new module and define a di.xml file in the etc directory of your module:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Thumbnail">
        <plugin name="custom_thumbnail_plugin" type="Vendor\Module\Plugin\ThumbnailPlugin" />
    </type>
</config>

2.Create a new class Vendor\Module\Plugin\ThumbnailPlugin and define the aroundExecute method:

<?php
namespace Vendor\Module\Plugin;

class ThumbnailPlugin
{
    protected $_objectManager;

    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager
    ) {
        $this->_objectManager = $objectManager;
    }

    public function aroundExecute(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Thumbnail $subject, \Closure $proceed)
    {
        // your code before the original execute() method is called
        $image = $this->_objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
        $image->open('media/wysiwyg/test_icon.png');
        $resultRaw = $subject->resultRawFactory->create();
        $resultRaw->setHeader('Content-Type', $image->getMimeType());
        $resultRaw->setContents($image->getImage());
        return $resultRaw;
        // your code after the original execute() method is called
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.