Hi i am trying to add a custom import fucntionality for my module but I got this error:-
Fatal error: Uncaught Error: Call to a member function getUrl() on null in E:\xampp\htdocs\m2\vendor\magento\framework\View\Element\AbstractBlock.php:775 Stack trace: #0 E:\xampp\htdocs\m2\vendor\magento\module-backend\Block\Widget\Tabs.php(141): Magento\Framework\View\Element\AbstractBlock->getUrl() #1 [internal function]: Magento\Backend\Block\Widget\Tabs->addTab('importpincode', 'netsmartz_pinco...') #2 E:\xampp\htdocs\m2\vendor\magento\framework\View\Layout\Generator\Block.php(298): call_user_func_array(Array, Array) #3 E:\xampp\htdocs\m2\vendor\magento\framework\View\Layout\Generator\Block.php(169): Magento\Framework\View\Layout\Generator\Block->generateAction(Object(Netsmartz\PincodeChecker\Block\Adminhtml\Importpincode\Edit\Tabs), 'addTab', Array) #4 E:\xampp\htdocs\m2\vendor\magento\framework\View\Layout\GeneratorPool.php(81): Magento\Framework\View\Layout\Generator\Block->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context)) #5 E:\xampp\htdocs\m2\ve in E:\xampp\htdocs\m2\vendor\magento\framework\View\Element\AbstractBlock.php on line 775
here is my code:-
<?php
namespace vendor\module\Block\Adminhtml\Importpincode\Edit\Tab;
class Importpincode extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
protected $_assetRepo;
public function __construct(
\Magento\Framework\View\Asset\Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
/**
* Prepare form
*
* @return $this
*/
protected function _prepareForm()
{
$path = $this->_assetRepo->getUrl("vendor_module::importsample/sample.csv");
$form = $this->_formFactory->create();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storemanager = $objectManager->create('Magento\Store\Model\StoreManagerInterface');
$fieldset = $form->addFieldset(
'base_fieldset',
[
'legend' => __('Import Pincodes'),
'class' => 'fieldset-wide'
]
);
$importdata_script = $fieldset->addField(
'file',
'file',
[
'name' => 'file',
'label' => __('Upload File'),
'title' => __('Upload File'),
'required' => true,
]
);
$importdata_script->setAfterElementHtml("
<span id='sample-file-span' ><a id='sample-file-link' href='".$path."' >Download Sample File</a></span>
");
$this->setForm($form);
return parent::_prepareForm();
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('Import Pincodes');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
return true;
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
}
any help on this will be great