1

How to change image path of a Field of type "image" ?

In my custom module adminhtml form I am using field as type "image" to show thum image. I want to change the default path of this thum and want to use my custom path here, as my image upload path is different.

Here is my addField example :

$fieldset->addField(
        'image',
        'image',
        array(
            'name' => 'image',
            'label' => __('Example Image'),
            'title' => __('Example Image'),
            'required' => false,
        )
    );
2

You can use custom type and extend magento image type

change your code in your form.php as below

$fieldset->addType('custom_image','VendorName\ModuleName\Helper\Image\Custom');
$fieldset->addField(
    'image',
    'custom_image',
    array(
        'name' => 'image',
        'label' => __('Your Lable'),
        'title' => __('Your Title'),
        'required' => false,
    )
);

Create that Block class and extend \Magento\Framework\Data\Form\Element\Image

namespace VendorName\ModuleName\Helper\Image;

class Custom extends \Magento\Framework\Data\Form\Element\Image
{
    public function _getUrl()
    {   
        $url = 'YourModulePath'.$this->getValue(); 
        return $url;
    }
}

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.