1

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

update:- enter image description here

2
  • have you tried by calling parent constructor as @Msquare answer? Commented Feb 17, 2020 at 9:28
  • yeah check the updated question Commented Feb 17, 2020 at 9:45

2 Answers 2

8

Try This

<?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\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\View\Asset\Repository $assetRepo, array $data = [] ) { $this->_assetRepo = $assetRepo; parent::__construct($context, $registry, $formFactory, $data); } /** * 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; } } 

enter image description here

[Update]

For UI Component

app/code/VendoreName/ModuleName/view/adminhtml/ui_component

import_storelocation_form.xml

<?xml version="1.0" encoding="UTF-8"?> <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <argument name="data" xsi:type="array"> <item name="js_config" xsi:type="array"> <item name="provider" xsi:type="string">import_storelocation_form.import_storelocation_form_data_source</item> <item name="deps" xsi:type="string">import_storelocation_form.import_storelocation_form_data_source</item> </item> <item name="label" xsi:type="string" translate="true">General Information</item> <item name="config" xsi:type="array"> <item name="dataScope" xsi:type="string">data</item> <item name="namespace" xsi:type="string">import_storelocation_form</item> </item> <item name="spinner" xsi:type="string">general_information</item> <item name="buttons" xsi:type="array"> <item name="back" xsi:type="string">VendoreName\ModuleName\Block\Adminhtml\Storelocator\Edit\Button\Back</item> <item name="reset" xsi:type="string">VendoreName\ModuleName\Block\Adminhtml\Storelocator\Edit\Button\Reset</item> <item name="save" xsi:type="string">VendoreName\ModuleName\Block\Adminhtml\Storelocator\Edit\Button\SaveImportData</item> </item> <item name="template" xsi:type="string">templates/form/collapsible</item> </argument> <dataSource name="import_storelocation_form_data_source"> <argument name="dataProvider" xsi:type="configurableObject"> <argument name="class" xsi:type="string">VendoreName\ModuleName\Model\DataProvider</argument> <argument name="name" xsi:type="string">import_storelocation_form_data_source</argument> <argument name="primaryFieldName" xsi:type="string">entity_id</argument> <argument name="requestFieldName" xsi:type="string">entity_id</argument> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="submit_url" xsi:type="url" path="*/*/saveimportdata"/> </item> </argument> </argument> <argument name="data" xsi:type="array"> <item name="js_config" xsi:type="array"> <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item> </item> </argument> </dataSource> <fieldset name="general_information"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="collapsible" xsi:type="boolean">false</item> <item name="label" xsi:type="string" translate="true"></item> <item name="sortOrder" xsi:type="number">20</item> </item> </argument> <field name="importfile"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="dataType" xsi:type="string">string</item> <item name="source" xsi:type="string">importfile</item> <item name="label" xsi:type="string" translate="true">Upload File</item> <item name="visible" xsi:type="boolean">true</item> <item name="allowedExtensions" xsi:type="string">csv xls</item> <item name="maxFileSize" xsi:type="number">2097152</item> <item name="formElement" xsi:type="string">fileUploader</item> <item name="previewTmpl" xsi:type="string">VendoreName_ModuleName/file-preview</item> <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item> <item name="dataScope" xsi:type="string">importfile</item> <item name="notice" xsi:type="string" translate="true">Allow File Types:- .csv and .xls</item> <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> <item name="uploaderConfig" xsi:type="array"> <item name="url" xsi:type="url" path="storelocator/storelocator/Importupload" > <param name="target_element_id">importfile</param> <param name="type">image</param> </item> </item> </item> </argument> </field> </fieldset> </form> 

Click Here to download the source code for the UI component

enter image description here

0
0

i got this error. how to fix this:

1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Rakuten\MemberCard\Block\Adminhtml\Card\Import, Magento\Backend\Block\Widget\Form\Generic::__construct(): Argument #2 ($registry) must be of type Magento\Framework\Registry, array given, called in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Block/Adminhtml/Card/Import.php on line 23 Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Rakuten\MemberCard\Block\Adminhtml\Card\Import, Magento\Backend\Block\Widget\Form\Generic::__construct(): Argument #2 ($registry) must be of type Magento\Framework\Registry, array given, called in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Block/Adminhtml/Card/Import.php on line 23 <pre>#1 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56] #2 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/View/Element/BlockFactory.php:44] #3 Magento\Framework\View\Element\BlockFactory->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:272] #4 Magento\Framework\View\Layout\Generator\Block->getBlockInstance() called at [vendor/magento/framework/View/Layout/Generator/Block.php:252] #5 Magento\Framework\View\Layout\Generator\Block->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:229] #6 Magento\Framework\View\Layout\Generator\Block->generateBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:134] #7 Magento\Framework\View\Layout\Generator\Block->process() called at [vendor/magento/framework/View/Layout/GeneratorPool.php:93] #8 Magento\Framework\View\Layout\GeneratorPool->process() called at [vendor/magento/framework/View/Layout.php:365] #9 Magento\Framework\View\Layout->generateElements() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:68] #10 Magento\Framework\View\Layout\Interceptor->generateElements() called at [vendor/magento/framework/View/Layout/Builder.php:129] #11 Magento\Framework\View\Layout\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Page/Builder.php:65] #12 Magento\Framework\View\Page\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Layout/Builder.php:65] #13 Magento\Framework\View\Layout\Builder->build() called at [vendor/magento/framework/View/Page/Config.php:227] #14 Magento\Framework\View\Page\Config->build() called at [vendor/magento/framework/View/Page/Config.php:250] #15 Magento\Framework\View\Page\Config->getTitle() called at [app/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import.php:32] #16 Rakuten\MemberCard\Controller\Adminhtml\Card\Import->execute() called at [vendor/magento/framework/Interception/Interceptor.php:58] #17 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #18 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #19 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import/Interceptor.php:23] #20 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:111] #21 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/module-backend/App/AbstractAction.php:151] #22 Magento\Backend\App\AbstractAction->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58] #23 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #24 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-backend/App/Action/Plugin/Authentication.php:145] #25 Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135] #26 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #27 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import/Interceptor.php:32] #28 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:245] #29 Magento\Framework\App\FrontController->getActionResponse() called at [vendor/magento/framework/App/FrontController.php:212] #30 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:147] #31 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58] #32 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #33 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #34 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23] #35 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116] #36 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23] #37 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264] #38 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30] </pre> 
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.