0

I am using Magento 2.4.2 community edition and I want to allow SVG upload across everywhere in magento admin. I have tried below code to achieve it but no luck.

Firstly, I tried to add svg in allowed extensions list using below code. I was hoping, it will allow svg upload in Wysiwyg editor.

<type name="Magento\Cms\Model\Wysiwyg\Images\Storage">
    <arguments>
        <argument name="extensions" xsi:type="array">
            <item name="allowed" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg</item>
            </item>
            <item name="image_allowed" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg</item>
            </item>
            <item name="media_allowed" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg</item>
            </item>
        </argument>
    </arguments>
</type>

Then, I tried to create Plugin which will allow svg from each upload button. But no luck.

<type name="Magento\Framework\File\Uploader">
    <plugin sortOrder="1" name="SvgUploadPlugin" type="Vendor\Module\Plugin\UploaderPlugin"/>
</type>

Plugin Code:

class UploaderPlugin extends Action
{
    public function __construct(Context $context)
    {
        parent::__construct($context);
    }

    public function aroundSetAllowedExtensions(\Magento\Framework\File\Uploader $subject, \Closure $proceed, $extensions = [])
    {
        if (!in_array('svg', $extensions)) {
            $extensions[] = 'svg';
        }
        return $proceed($extensions);
    }

    public function execute() {}
}

If anyone have achieved it, please let me know the solution. Thanks in advance.

0

You can try this free plugin. it should help. there are fixes for 2.4 as well

https://github.com/MagestyApps/module-web-images

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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