0

I have created a form for my extension using this tutorial.

My problem is that I have no buttons (save, delete, etc) in my actions bar.

I can add Save and Continue Edit, as the tutorial has, and this shows. However, the other default buttons are missing.

Below is my Edit.php:

namespace Wildcard\QuantityGroups\Block\Adminhtml\Quantitygroups;

use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;

class Edit extends Container
{

    /** @var  Registry $_coreRegistry */
    protected $_coreRegistry;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;

        parent::__construct($context, $data);
    }

    protected function _construct()
    {

        $this->_objectId   = 'id';
        $this->_blockGroup = 'Wildcard_QuantityGroups';
        $this->_controller = 'adminhtml_quantitygroups';

        $this->buttonList->add(
            'save_and_continue',
            [
                'label'          => __('Save and Continue Edit'),
                'class'          => 'save',
                'data_attribute' => [
                    'mage-init' => [
                        'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
                    ],
                ]
            ],
            10
        );

        if ($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getId()) {
            $this->buttonList->remove('reset');
        }
    }

    public function getHeaderText()
    {
        if ($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getId()) {
            return __("Edit Quantity Group '%1'", $this->escapeHtml($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getTitle()));
        } else {
            return __('New Quantity Group');
        }
    }

    protected function _isAllowedAction($resourceId)
    {
        return $this->_authorization->isAllowed($resourceId);
    }

    protected function _getSaveAndContinueUrl()
    {
        return $this->getUrl('quantitygroups/actions/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);
    }

Can someone please let me know what I am missing? I have gone through core extensions and other tutorials to see what I might be missing, but cannot find it!

I am using Magento 2.1.5.

Please let me know if I need to share more code.

  • 1
    if ($this->_isAllowedAction('Wildcard_QuantityGroups::save')) { can you remove that and check it – Sunil Patel May 4 '17 at 8:48
  • That didn't do anything – Wildcard27 May 4 '17 at 8:57
  • it is checking permission for that resource. – Sunil Patel May 4 '17 at 9:08
  • No, I mean removing it did not help. I know what the line does. – Wildcard27 May 4 '17 at 9:30
  • @sunilpatel Do you have any other suggestions? I really need to get this working – Wildcard27 May 4 '17 at 9:58
2

Try below code :

<?php
namespace Wildcard\QuantityGroups\Block\Adminhtml\Quantitygroups;

use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;

class Edit extends Container
{

    /** @var  Registry $_coreRegistry */
    protected $_coreRegistry;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;

        parent::__construct($context, $data);
    }

    protected function _construct()
    {

        $this->_objectId   = 'id';
        $this->_blockGroup = 'Wildcard_QuantityGroups';
        $this->_controller = 'adminhtml_quantitygroups';

        parent::_construct();

        $this->buttonList->add(
            'save_and_continue',
            [
                'label'          => __('Save and Continue Edit'),
                'class'          => 'save',
                'data_attribute' => [
                    'mage-init' => [
                        'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
                    ],
                ],
            ],
            10
        );

        if ($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getId()) {
            $this->buttonList->remove('reset');
        }
    }

    public function getHeaderText()
    {
        if ($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getId()) {
            return __("Edit Quantity Group '%1'", $this->escapeHtml($this->_coreRegistry->registry('quantityGroups_quantityGroup')->getTitle()));
        } else {
            return __('New Quantity Group');
        }
    }

    protected function _isAllowedAction($resourceId)
    {
        return $this->_authorization->isAllowed($resourceId);
    }

    protected function _getSaveAndContinueUrl()
    {
        return $this->getUrl('quantitygroups/actions/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);
    }
}

You missed parent::_construct(); line in function protected function _construct()

  • Absolute legend. Thank you! I think I have been working on this for too long! – Wildcard27 May 4 '17 at 10:14
0

Add following detail in your construct function.

 protected function _construct()
    {
        parent::_construct();
        $this->buttonList->update('save', 'label', __('Save'));        
        $this->buttonList->update('delete', 'label', __('Delete'));
    }

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.