PickupBackButton.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Block\Adminhtml\PageAction;
  6. use Magento\Backend\Block\Template\Context;
  7. use Magento\Backend\Block\Widget\Button;
  8. use Magento\Framework\App\Response\RedirectInterface;
  9. /**
  10. * Action Button to Order View or Pickup Listing Page
  11. *
  12. * @api
  13. * @package Temando\Shipping\Block
  14. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  15. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link https://www.temando.com/
  17. */
  18. class PickupBackButton extends Button
  19. {
  20. /**
  21. * @var RedirectInterface
  22. */
  23. private $redirect;
  24. /**
  25. * PickupBackButton constructor.
  26. * @param Context $context
  27. * @param RedirectInterface $redirect
  28. * @param mixed[] $data
  29. */
  30. public function __construct(
  31. Context $context,
  32. RedirectInterface $redirect,
  33. array $data = []
  34. ) {
  35. $this->redirect = $redirect;
  36. parent::__construct($context, $data);
  37. }
  38. /**
  39. * Add button data
  40. *
  41. * @return Button
  42. */
  43. protected function _beforeToHtml()
  44. {
  45. $backUrl = $this->redirect->getRefererUrl();
  46. $this->setData('label', __('Back'));
  47. $this->setData('class', 'back');
  48. $this->setData('id', 'back');
  49. $this->setData('onclick', sprintf("setLocation('%s')", $backUrl));
  50. return parent::_beforeToHtml();
  51. }
  52. }