I would like add multipart-form/data to Magento2's Admin Form.
Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Block\Adminhtml\Group\Edit\Form"
type="Vednor\Module\Block\Adminhtml\Group\Edit\Form" />
</config>
I've override below file
magento-customer/Block/Adminhtml/Group/Edit/Form.php
TO
Vendor/Module/Block/Adminhtml/Group/Edit/Form.php
<?php
namespace Vivek\ShopAsGroup\Block\Adminhtml\Group\Edit;
use Magento\Customer\Controller\RegistryConstants;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Framework\Data\Form as DataForm;
class Form extends \Magento\Customer\Block\Adminhtml\Group\Edit\Form
{
protected $formFactory;
public function __construct(
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\UrlInterface $url,
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Tax\Model\TaxClass\Source\Customer $taxCustomer,
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
\Magento\Tax\Helper\Data $taxHelper,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlInterface,
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
\Magento\Customer\Api\Data\GroupInterfaceFactory $groupDataFactory,
array $data = []
) {
$this->_responseFactory = $responseFactory;
$this->_url = $url;
$this->_taxCustomer = $taxCustomer;
$this->_taxHelper = $taxHelper;
$this->_storeManager = $storeManager;
$this->uploaderFactory = $uploaderFactory;
$this->_urlInterface = $urlInterface;
$this->formFactory = $formFactory;
$this->groupDataFactory = $groupDataFactory;
$this->_resultLayoutFactory = $resultLayoutFactory;
parent::__construct($context, $registry, $formFactory, $data);
}
protected function _prepareForm()
{
parent::_prepareForm(); //add this
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'enctype' => 'multipart/form-data'
]
]
);
$form->setUseContainer(true);
$this->setForm($form);
return $this; //chnage this
}
}
I did upgrade and Deploy but it not seems to be working for me.
Took reference from Magento StackExchange
What i am missing ? Any Guide..
Thanks in Advance.