Magento 2 : How to change default path of a Field of type “image”?
-
06-10-2020 - |
문제
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,
)
);
해결책
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;
}
}
제휴하지 않습니다 magento.stackexchange