3

I want to show the button in my custom module (admin page)

but I am getting an error

I want to add a button and how I add action process for that button

i already tried this answer : (https://magento.stackexchange.com/a/212656/73525 )

GenericButton.php

    <?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\Edit;

use Magento\Backend\Block\Widget\Context;
//use FME\News\Api\NewsRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
 * Class GenericButton
 */
class GenericButton
{
    /**
     * @var Context
     */
    protected $context;

    /**
     * @var BlockRepositoryInterface
     */
    protected $blockRepository;

    /**
     * @param Context $context
     * @param BlockRepositoryInterface $blockRepository
     */
    public function __construct(
        Context $context
    ) {
        $this->context = $context;
        //$this->blockRepository = $blockRepository;
    }

    /**
     * Return CMS block ID
     *
     * @return int|null
     */
    public function getBlockId()
    {
/*
        {
            return $this->blockRepository->getById(
                $this->context->getRequest()->getParam('news_id')
            )->getId();
        }  */
        return null;
    }

    /**
     * Generate url by route and parameters
     *
     * @param   string $route
     * @param   array $params
     * @return  string
     */
    public function getUrl($route = '', $params = [])
    {
        return $this->context->getUrlBuilder()->getUrl($route, $params);
    }
}

SaveandContinuebutton.php

<?php

namespace  Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
 * Class SaveAndContinueButton
 */
class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
{

    public function getButtonData()
    {
        return [
            'label' => __('ADmin pproval'),
            'class' => 'save',
            'on_click' => 'location.reload();',
            'sort_order' => 30
        ];
    }
}

view/adminhtml/uicomponent/custommodule_edit.xml

<?xml version="1.0"?>
<!-- /**
 * Webkul Software
 *
 * @category  Webkul
 * @package   Webkul_Mpquotesystem
 * @author    Webkul
 * @copyright Copyright (c) 2010-2018 Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */ -->
<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="buttons" xsi:type="array">
        <item name="save_and_continue" xsi:type="string">Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\Edit\SaveAndContinueButton</item>
    </item>

    </argument>
</form>

when clicking that admin custom module page :

Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to a member function getRequestFieldName() on null in /var/www/html/equpo2/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line

0

Just change your SaveAndContinueButton file: and chek after clearing generated folder

       namespace Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\Edit;

        use Magento\Customer\Api\AccountManagementInterface;
        use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

        class SaveAndContinueButton  implements ButtonProviderInterface
        {

            public function getButtonData()
            {
                return [
                    'label' => __('Save and Continue Edit'),
                    'class' => 'save',
                    'data_attribute' => [
                        'mage-init' => ['button' => ['event' => 'saveAndContinueEdit']],
                        'form-role' => 'save',
                    ],
                    'sort_order' => 80,
                ];
            }

        }
  • Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to a member function getRequestFieldName() on null in /var/www/html/equpo2/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0 i am getting error – prabhakaran7 Mar 14 at 5:51
  • @prabhakaran7 Don't you have add dataSource code in view/adminhtml/uicomponent/custommodule_edit.xml ? if yes please add in question – Rutvee Sojitra Mar 14 at 5:54
  • yes no datasource what i do – prabhakaran7 Mar 14 at 5:57
  • please follw and check where you did mistake pierrefay.com/magento2-training/… – Rutvee Sojitra Mar 14 at 5:59
  • this page only one form – prabhakaran7 Mar 14 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.