Custom button in adminhtml edit moduleI created a custom module ,but getting error, not able to figure out...

Traveling through the asteriod belt?

How would an AI self awareness kill switch work?

Does theoretical physics suggest that gravity is the exchange of gravitons or deformation/bending of spacetime?

Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?

My cat mixes up the floors in my building. How can I help him?

Which one of these password policies is more secure?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

How can animals be objects of ethics without being subjects as well?

A title for a history book

It took me a lot of time to make this, pls like. (YouTube Comments #1)

How to deal with an incendiary email that was recalled

Writing a character who is going through a civilizing process without overdoing it?

Why has the mole been redefined for 2019?

Equation with several exponents

Can placing a counter on a creature after it has been assigned as an attacker remove it from combat

Simple text-based tic-tac-toe

Why is working on the same position for more than 15 years not a red flag?

Why avoid shared user accounts?

How to count the characters of jar files by wc

Am I a Rude Number?

Pronunciation of umlaut vowels in the history of German

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Finding a mistake using Mayer-Vietoris

Why do neural networks need so many training examples to perform?



Custom button in adminhtml edit module


I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Submit Files in Admin Form - Magento 1.7Magento 2 Add new field to Magento_User admin formMagento 2: Plugin class does not existForm is not displayed on panel admin Magento 2Magento offline custom Payment method with drop down listMagento 2 : Error when Add WYSIWYG Editor to Block FormMagento 2 Create dynamic array From different Model Collection to use in multi select in gridImportExport module: can't work custom file adapter in magento2?Magento 2.3 Can't view module's front end page output?













0















I have created a module to upload a csv and create an import of custom data in it.
My form is well displayed and my custom button too. But when I click on the button nothing happens.



Any idea ?



app/code/Vendor/Branches/view/adminhtml/layout/branches_import_index.xml



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>
Branches
</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorBranchesBlockAdminhtmlImportEdit" name="branches.import.form.container"/>
</referenceContainer>
</body>
</page>


app/code/Vendor/Branches/Block/Adminhtml/Import/Edit.php



<?php
namespace VendorBranchesBlockAdminhtmlImport;

class Edit extends MagentoBackendBlockWidgetFormContainer
{
/**
* Internal constructor
*
* @return void
*/
protected function _construct()
{
$this->_objectId = 'branches_import_id';
$this->_blockGroup = 'Vendor_Branches';
$this->_controller = 'adminhtml_import';

parent::_construct();
$this->removeButton('back')->removeButton('reset')->removeButton('save');
$this->buttonList->add(
'branches_import',
[
'label' => __('Import Branches'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save', 'target' => '#edit_form'],
],
]
],
1,
10
);
}

/**
* Get header text
*
* @return MagentoFrameworkPhrase
*/
public function getHeaderText()
{
return __('Import');
}

/**
* Check whether is allowed action
*
* @param string $resourceId
* @return bool
*/
protected function _isAllowedAction($resourceId)
{
return $this->_authorization->isAllowed($resourceId);
}
}


app/code/Vendor/Branches/Block/Adminhtml/Import/Edit/Form.php



<?php
namespace VendorBranchesBlockAdminhtmlImportEdit;

use MagentoStoreModelStoreManagerInterface;

class Form extends MagentoBackendBlockWidgetFormGeneric
{
/**
* @var StoreManagerInterface
*/
protected $storeManager;

/**
* @var MagentoImportExportModelSourceExportFormatFactory
*/
protected $_formatFactory;

/**
* @param MagentoBackendBlockTemplateContext $context
* @param MagentoFrameworkRegistry $registry
* @param MagentoFrameworkDataFormFactory $formFactory
* @param StoreManagerInterface $storeManager
* @param MagentoImportExportModelSourceExportFormatFactory $formatFactory
* @param array $data
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoFrameworkDataFormFactory $formFactory,
StoreManagerInterface $storeManager,
MagentoImportExportModelSourceExportFormatFactory $formatFactory,
array $data = []
) {
$this->storeManager = $storeManager;
$this->_formatFactory = $formatFactory;
parent::__construct($context, $registry, $formFactory, $data);
}

/**
* Prepare form before rendering HTML.
*
* @return $this
*/
protected function _prepareForm()
{
/** @var MagentoFrameworkDataForm $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getUrl('*/*/import'),
'method' => 'post',
],
]
);

$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
$fieldset->addField(
'store',
'select',
[
'name' => 'store',
'title' => __('Store'),
'label' => __('Store'),
'required' => false,
'values' => $this->getStoreData()
]
);
$fieldset->addField(
MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
'file',
[
'name' => MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
'label' => __('Select File to Import'),
'title' => __('Select File to Import'),
'required' => true,
'class' => 'input-file'
]
);


$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();
}

/**
* Return array stores.
*
* @return array
*/
private function getStoreData(){
$storeManagerDataList = $this->storeManager->getStores();
$options = array();

foreach ($storeManagerDataList as $key => $value) {
$options[] = ['value' => $key, 'label' => $value['code'].' - '.$value['name']];
}
return $options;
}
}


Thank you !









share



























    0















    I have created a module to upload a csv and create an import of custom data in it.
    My form is well displayed and my custom button too. But when I click on the button nothing happens.



    Any idea ?



    app/code/Vendor/Branches/view/adminhtml/layout/branches_import_index.xml



    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
    <title>
    Branches
    </title>
    </head>
    <body>
    <referenceContainer name="content">
    <block class="VendorBranchesBlockAdminhtmlImportEdit" name="branches.import.form.container"/>
    </referenceContainer>
    </body>
    </page>


    app/code/Vendor/Branches/Block/Adminhtml/Import/Edit.php



    <?php
    namespace VendorBranchesBlockAdminhtmlImport;

    class Edit extends MagentoBackendBlockWidgetFormContainer
    {
    /**
    * Internal constructor
    *
    * @return void
    */
    protected function _construct()
    {
    $this->_objectId = 'branches_import_id';
    $this->_blockGroup = 'Vendor_Branches';
    $this->_controller = 'adminhtml_import';

    parent::_construct();
    $this->removeButton('back')->removeButton('reset')->removeButton('save');
    $this->buttonList->add(
    'branches_import',
    [
    'label' => __('Import Branches'),
    'class' => 'save primary',
    'data_attribute' => [
    'mage-init' => [
    'button' => ['event' => 'save', 'target' => '#edit_form'],
    ],
    ]
    ],
    1,
    10
    );
    }

    /**
    * Get header text
    *
    * @return MagentoFrameworkPhrase
    */
    public function getHeaderText()
    {
    return __('Import');
    }

    /**
    * Check whether is allowed action
    *
    * @param string $resourceId
    * @return bool
    */
    protected function _isAllowedAction($resourceId)
    {
    return $this->_authorization->isAllowed($resourceId);
    }
    }


    app/code/Vendor/Branches/Block/Adminhtml/Import/Edit/Form.php



    <?php
    namespace VendorBranchesBlockAdminhtmlImportEdit;

    use MagentoStoreModelStoreManagerInterface;

    class Form extends MagentoBackendBlockWidgetFormGeneric
    {
    /**
    * @var StoreManagerInterface
    */
    protected $storeManager;

    /**
    * @var MagentoImportExportModelSourceExportFormatFactory
    */
    protected $_formatFactory;

    /**
    * @param MagentoBackendBlockTemplateContext $context
    * @param MagentoFrameworkRegistry $registry
    * @param MagentoFrameworkDataFormFactory $formFactory
    * @param StoreManagerInterface $storeManager
    * @param MagentoImportExportModelSourceExportFormatFactory $formatFactory
    * @param array $data
    */
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoFrameworkRegistry $registry,
    MagentoFrameworkDataFormFactory $formFactory,
    StoreManagerInterface $storeManager,
    MagentoImportExportModelSourceExportFormatFactory $formatFactory,
    array $data = []
    ) {
    $this->storeManager = $storeManager;
    $this->_formatFactory = $formatFactory;
    parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
    * Prepare form before rendering HTML.
    *
    * @return $this
    */
    protected function _prepareForm()
    {
    /** @var MagentoFrameworkDataForm $form */
    $form = $this->_formFactory->create(
    [
    'data' => [
    'id' => 'edit_form',
    'action' => $this->getUrl('*/*/import'),
    'method' => 'post',
    ],
    ]
    );

    $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
    $fieldset->addField(
    'store',
    'select',
    [
    'name' => 'store',
    'title' => __('Store'),
    'label' => __('Store'),
    'required' => false,
    'values' => $this->getStoreData()
    ]
    );
    $fieldset->addField(
    MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
    'file',
    [
    'name' => MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
    'label' => __('Select File to Import'),
    'title' => __('Select File to Import'),
    'required' => true,
    'class' => 'input-file'
    ]
    );


    $form->setUseContainer(true);
    $this->setForm($form);

    return parent::_prepareForm();
    }

    /**
    * Return array stores.
    *
    * @return array
    */
    private function getStoreData(){
    $storeManagerDataList = $this->storeManager->getStores();
    $options = array();

    foreach ($storeManagerDataList as $key => $value) {
    $options[] = ['value' => $key, 'label' => $value['code'].' - '.$value['name']];
    }
    return $options;
    }
    }


    Thank you !









    share

























      0












      0








      0








      I have created a module to upload a csv and create an import of custom data in it.
      My form is well displayed and my custom button too. But when I click on the button nothing happens.



      Any idea ?



      app/code/Vendor/Branches/view/adminhtml/layout/branches_import_index.xml



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
      <title>
      Branches
      </title>
      </head>
      <body>
      <referenceContainer name="content">
      <block class="VendorBranchesBlockAdminhtmlImportEdit" name="branches.import.form.container"/>
      </referenceContainer>
      </body>
      </page>


      app/code/Vendor/Branches/Block/Adminhtml/Import/Edit.php



      <?php
      namespace VendorBranchesBlockAdminhtmlImport;

      class Edit extends MagentoBackendBlockWidgetFormContainer
      {
      /**
      * Internal constructor
      *
      * @return void
      */
      protected function _construct()
      {
      $this->_objectId = 'branches_import_id';
      $this->_blockGroup = 'Vendor_Branches';
      $this->_controller = 'adminhtml_import';

      parent::_construct();
      $this->removeButton('back')->removeButton('reset')->removeButton('save');
      $this->buttonList->add(
      'branches_import',
      [
      'label' => __('Import Branches'),
      'class' => 'save primary',
      'data_attribute' => [
      'mage-init' => [
      'button' => ['event' => 'save', 'target' => '#edit_form'],
      ],
      ]
      ],
      1,
      10
      );
      }

      /**
      * Get header text
      *
      * @return MagentoFrameworkPhrase
      */
      public function getHeaderText()
      {
      return __('Import');
      }

      /**
      * Check whether is allowed action
      *
      * @param string $resourceId
      * @return bool
      */
      protected function _isAllowedAction($resourceId)
      {
      return $this->_authorization->isAllowed($resourceId);
      }
      }


      app/code/Vendor/Branches/Block/Adminhtml/Import/Edit/Form.php



      <?php
      namespace VendorBranchesBlockAdminhtmlImportEdit;

      use MagentoStoreModelStoreManagerInterface;

      class Form extends MagentoBackendBlockWidgetFormGeneric
      {
      /**
      * @var StoreManagerInterface
      */
      protected $storeManager;

      /**
      * @var MagentoImportExportModelSourceExportFormatFactory
      */
      protected $_formatFactory;

      /**
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param MagentoFrameworkDataFormFactory $formFactory
      * @param StoreManagerInterface $storeManager
      * @param MagentoImportExportModelSourceExportFormatFactory $formatFactory
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkDataFormFactory $formFactory,
      StoreManagerInterface $storeManager,
      MagentoImportExportModelSourceExportFormatFactory $formatFactory,
      array $data = []
      ) {
      $this->storeManager = $storeManager;
      $this->_formatFactory = $formatFactory;
      parent::__construct($context, $registry, $formFactory, $data);
      }

      /**
      * Prepare form before rendering HTML.
      *
      * @return $this
      */
      protected function _prepareForm()
      {
      /** @var MagentoFrameworkDataForm $form */
      $form = $this->_formFactory->create(
      [
      'data' => [
      'id' => 'edit_form',
      'action' => $this->getUrl('*/*/import'),
      'method' => 'post',
      ],
      ]
      );

      $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
      $fieldset->addField(
      'store',
      'select',
      [
      'name' => 'store',
      'title' => __('Store'),
      'label' => __('Store'),
      'required' => false,
      'values' => $this->getStoreData()
      ]
      );
      $fieldset->addField(
      MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
      'file',
      [
      'name' => MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
      'label' => __('Select File to Import'),
      'title' => __('Select File to Import'),
      'required' => true,
      'class' => 'input-file'
      ]
      );


      $form->setUseContainer(true);
      $this->setForm($form);

      return parent::_prepareForm();
      }

      /**
      * Return array stores.
      *
      * @return array
      */
      private function getStoreData(){
      $storeManagerDataList = $this->storeManager->getStores();
      $options = array();

      foreach ($storeManagerDataList as $key => $value) {
      $options[] = ['value' => $key, 'label' => $value['code'].' - '.$value['name']];
      }
      return $options;
      }
      }


      Thank you !









      share














      I have created a module to upload a csv and create an import of custom data in it.
      My form is well displayed and my custom button too. But when I click on the button nothing happens.



      Any idea ?



      app/code/Vendor/Branches/view/adminhtml/layout/branches_import_index.xml



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
      <title>
      Branches
      </title>
      </head>
      <body>
      <referenceContainer name="content">
      <block class="VendorBranchesBlockAdminhtmlImportEdit" name="branches.import.form.container"/>
      </referenceContainer>
      </body>
      </page>


      app/code/Vendor/Branches/Block/Adminhtml/Import/Edit.php



      <?php
      namespace VendorBranchesBlockAdminhtmlImport;

      class Edit extends MagentoBackendBlockWidgetFormContainer
      {
      /**
      * Internal constructor
      *
      * @return void
      */
      protected function _construct()
      {
      $this->_objectId = 'branches_import_id';
      $this->_blockGroup = 'Vendor_Branches';
      $this->_controller = 'adminhtml_import';

      parent::_construct();
      $this->removeButton('back')->removeButton('reset')->removeButton('save');
      $this->buttonList->add(
      'branches_import',
      [
      'label' => __('Import Branches'),
      'class' => 'save primary',
      'data_attribute' => [
      'mage-init' => [
      'button' => ['event' => 'save', 'target' => '#edit_form'],
      ],
      ]
      ],
      1,
      10
      );
      }

      /**
      * Get header text
      *
      * @return MagentoFrameworkPhrase
      */
      public function getHeaderText()
      {
      return __('Import');
      }

      /**
      * Check whether is allowed action
      *
      * @param string $resourceId
      * @return bool
      */
      protected function _isAllowedAction($resourceId)
      {
      return $this->_authorization->isAllowed($resourceId);
      }
      }


      app/code/Vendor/Branches/Block/Adminhtml/Import/Edit/Form.php



      <?php
      namespace VendorBranchesBlockAdminhtmlImportEdit;

      use MagentoStoreModelStoreManagerInterface;

      class Form extends MagentoBackendBlockWidgetFormGeneric
      {
      /**
      * @var StoreManagerInterface
      */
      protected $storeManager;

      /**
      * @var MagentoImportExportModelSourceExportFormatFactory
      */
      protected $_formatFactory;

      /**
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param MagentoFrameworkDataFormFactory $formFactory
      * @param StoreManagerInterface $storeManager
      * @param MagentoImportExportModelSourceExportFormatFactory $formatFactory
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkDataFormFactory $formFactory,
      StoreManagerInterface $storeManager,
      MagentoImportExportModelSourceExportFormatFactory $formatFactory,
      array $data = []
      ) {
      $this->storeManager = $storeManager;
      $this->_formatFactory = $formatFactory;
      parent::__construct($context, $registry, $formFactory, $data);
      }

      /**
      * Prepare form before rendering HTML.
      *
      * @return $this
      */
      protected function _prepareForm()
      {
      /** @var MagentoFrameworkDataForm $form */
      $form = $this->_formFactory->create(
      [
      'data' => [
      'id' => 'edit_form',
      'action' => $this->getUrl('*/*/import'),
      'method' => 'post',
      ],
      ]
      );

      $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
      $fieldset->addField(
      'store',
      'select',
      [
      'name' => 'store',
      'title' => __('Store'),
      'label' => __('Store'),
      'required' => false,
      'values' => $this->getStoreData()
      ]
      );
      $fieldset->addField(
      MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
      'file',
      [
      'name' => MagentoImportExportModelImport::FIELD_NAME_SOURCE_FILE,
      'label' => __('Select File to Import'),
      'title' => __('Select File to Import'),
      'required' => true,
      'class' => 'input-file'
      ]
      );


      $form->setUseContainer(true);
      $this->setForm($form);

      return parent::_prepareForm();
      }

      /**
      * Return array stores.
      *
      * @return array
      */
      private function getStoreData(){
      $storeManagerDataList = $this->storeManager->getStores();
      $options = array();

      foreach ($storeManagerDataList as $key => $value) {
      $options[] = ['value' => $key, 'label' => $value['code'].' - '.$value['name']];
      }
      return $options;
      }
      }


      Thank you !







      magento2 magento2.2 adminhtml





      share












      share










      share



      share










      asked 4 mins ago









      VinzVinz

      438313




      438313






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263920%2fcustom-button-in-adminhtml-edit-module%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263920%2fcustom-button-in-adminhtml-edit-module%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          夢乃愛華...