Question

I'm new at magento 2 and I'm trying to create a "SaveAndContinue" button.

I created the classes, but when i click the SaveAndContinue button on the form, it calls the "save" controller and not the "save and continue" controller. What could it be?

form.xml

            <button name="save_and_continue" class="Hub\Api\Block\Adminhtml\Data\Edit\Buttons\SaveAndContinue" />

SaveAndContinue button:

class SaveAndContinue extends Generic implements ButtonProviderInterface

{

/**
 * Get buttong attributes
 *
 * @return array
 */
public function getButtonData()
{
    return [
        'label' => __('Save and Continue Edit'),
        'class' => 'save',
        'data_attribute' => [
            'mage-init' => [
                'button' => ['event' => 'saveAndContinueEdit'],
            ],
        ],
        'sort_order' => 80,
    ];
}

}

Was it helpful?

Solution

As per the default behavior of magento clicking the Save and Continue Edit Button will take you to the "Save" Controller only.

However in the Save Controller you will get a URL Param called "back". If this parameter is present in the URL the control will be redirected to the Edit Page.

If the "back" parameter is not present it will redirect to the index page.(i.e Grid Page). The URL parameter will look like this below

save/key/50ae7415daa8cc17732a255e3da805d43e2dba60d74fcd54b1ba6e73ea2d30b3/back/edit
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top