PickupBackButton.php 1.46 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<?php
/**
 * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
 */
namespace Temando\Shipping\Block\Adminhtml\PageAction;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Button;
use Magento\Framework\App\Response\RedirectInterface;

/**
 * Action Button to Order View or Pickup Listing Page
 *
 * @api
 * @package Temando\Shipping\Block
 * @author  Christoph Aßmann <christoph.assmann@netresearch.de>
 * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @link    https://www.temando.com/
 */
class PickupBackButton extends Button
{
    /**
     * @var RedirectInterface
     */
    private $redirect;

    /**
     * PickupBackButton constructor.
     * @param Context $context
     * @param RedirectInterface $redirect
     * @param mixed[] $data
     */
    public function __construct(
        Context $context,
        RedirectInterface $redirect,
        array $data = []
    ) {
        $this->redirect = $redirect;

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

    /**
     * Add button data
     *
     * @return Button
     */
    protected function _beforeToHtml()
    {
        $backUrl = $this->redirect->getRefererUrl();
        $this->setData('label', __('Back'));
        $this->setData('class', 'back');
        $this->setData('id', 'back');
        $this->setData('onclick', sprintf("setLocation('%s')", $backUrl));

        return parent::_beforeToHtml();
    }
}