Good evening. I just recently started learning magento 2 and faced the following problem. I have an XML form that contains information, such as "Name, address, telephone" I need to create a block that will return which fields will be in the fieldset, but I dont know how I think that I'm calling the wrong class, I ask for help. Ty my code:
form.xml
<fieldset class="[Vendor]\[Module]\Block\Adminhtml\[Module]\Edit\Tab\Checkbox" />
di.xml
<preference for="Magento\Tax\Block\Adminhtml\Rate\Form" type="[Vendor]\[Module]\Block\Adminhtml\[Module]\Edit\Tab\Checkbox" />
[Vendor][Module]\Block\Adminhtml[Module]\Edit\Tab\Checkbox.php
class Checkbox extends \Magento\Tax\Block\Adminhtml\Rate\Form
{
protected $_taxData = null;
/**
* @var \Magento\Tax\Block\Adminhtml\Rate\Title\FieldsetFactory
*/
protected $_fieldsetFactory;
/**
* @var \Magento\Directory\Model\Config\Source\Country
*/
protected $_country;
/**
* @var \Magento\Directory\Model\RegionFactory
*/
protected $_regionFactory;
/**
* @var \Magento\Tax\Api\TaxRateRepositoryInterface
*/
protected $_taxRateRepository;
/**
* @var \Magento\Tax\Model\TaxRateCollection
*/
protected $_taxRateCollection;
/**
* @var \Magento\Tax\Model\Calculation\Rate\Converter
*/
protected $_taxRateConverter;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Directory\Model\RegionFactory $regionFactory
* @param \Magento\Directory\Model\Config\Source\Country $country
* @param \Magento\Tax\Block\Adminhtml\Rate\Title\FieldsetFactory $fieldsetFactory
* @param \Magento\Tax\Helper\Data $taxData
* @param \Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository
* @param \Magento\Tax\Model\TaxRateCollection $taxRateCollection
* @param \Magento\Tax\Model\Calculation\Rate\Converter $taxRateConverter
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Directory\Model\RegionFactory $regionFactory,
\Magento\Directory\Model\Config\Source\Country $country,
\Magento\Tax\Block\Adminhtml\Rate\Title\FieldsetFactory $fieldsetFactory,
\Magento\Tax\Helper\Data $taxData,
\Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository,
\Magento\Tax\Model\TaxRateCollection $taxRateCollection,
\Magento\Tax\Model\Calculation\Rate\Converter $taxRateConverter,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $regionFactory, $country, $fieldsetFactory, $taxData, $taxRateRepository, $taxRateCollection, $taxRateConverter, $data);
}
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
}
public function _prepareForm()
{
parent::_prepareForm();
$form = $this->getForm();
$fieldset = $form->п('new_fieldset',
array('legend'=>'GST Tax Rate Information')
);
$fieldset->addField('hsn_title', 'text',
array(
'label' => 'HSN Code',
'class' => 'input-text',
'name' => 'hsn_title',
'required' => false
)
);
$this->setForm($form);
return $this;
}