1

I want to override vendor/magento/module-page-builder/Controller/Adminhtml/ContentType/Image/Upload.php. please help me.

I want to allow webp extension in code using the override method.

enter image description here

1 Answer 1

3

You can follow these steps:

  1. Create a new module or use an existing one to contain your customizations. For example, you can create a module called Vendor_Module.

  2. In your module directory, create a new file called di.xml under Vendor/Module/etc/adminhtml/.

  3. Add the following code to di.xml to override the Upload.php file:

    <preference for="Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload" type="Vendor\Module\Controller\Adminhtml\ContentType\Image\Upload" />
    
  1. Create a new file called Upload.php under Vendor/Module/Controller/Adminhtml/ContentType/Image/.

  2. Copy the contents of vendor/magento/module-page-builder/Controller/Adminhtml/ContentType/Image/Upload.php into your new Upload.php file.

  3. Modify the code in your Upload.php file to allow the webp extension. For example, you can add the following code to the isAllowedExtension method:

    case 'webp':
    return true;
    

This will allow the webp extension to be uploaded along with the other allowed extensions.

  1. Save your changes and refresh the Magento cache.

Once you have completed these steps, your custom Upload.php file will be used instead of the original file in Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload. The webp extension will now be allowed for image uploads.

2
  • Thank you @Navneet Sharma It is working fine. :) Commented Mar 14, 2023 at 10:36
  • This answer also helpful : magecomp.com/blog/… Commented Mar 14, 2023 at 11:20

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.