LocationComponent.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Configuration;
  6. use Temando\Shipping\Model\LocationInterface;
  7. use Temando\Shipping\Block\Adminhtml\Template\AbstractComponent;
  8. /**
  9. * Temando Locations Layout Block
  10. *
  11. * @package Temando\Shipping\Block
  12. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  13. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  14. * @link http://www.temando.com/
  15. *
  16. * @api
  17. * @deprecated since 1.0.5 | Block data is provided by view model
  18. * @see \Temando\Shipping\ViewModel\Location\LocationEdit
  19. */
  20. class LocationComponent extends AbstractComponent
  21. {
  22. /**
  23. * Add Back Button.
  24. *
  25. * @return \Magento\Backend\Block\Widget\Container
  26. */
  27. protected function _prepareLayout()
  28. {
  29. $buttonData = [
  30. 'label' => __('Back'),
  31. 'onclick' => sprintf("window.location.href = '%s';", $this->getLocationsPageUrl()),
  32. 'class' => 'back',
  33. 'sort_order' => 10
  34. ];
  35. $this->buttonList->add('back', $buttonData);
  36. return parent::_prepareLayout();
  37. }
  38. /**
  39. * Obtain locations grid url
  40. *
  41. * @return string
  42. */
  43. public function getLocationsPageUrl()
  44. {
  45. return $this->getUrl('temando/configuration_location/index');
  46. }
  47. /**
  48. * Obtain Add New Carrier url.
  49. *
  50. * @return string
  51. */
  52. public function getNewLocationPageUrl()
  53. {
  54. return $this->getUrl('temando/configuration_location/new');
  55. }
  56. /**
  57. * Obtain the Temando location id that is passed from grid to edit component.
  58. * Think of it as a GUID rather than a location id in the local storage.
  59. *
  60. * @return string The Temando location id
  61. */
  62. public function getLocationId()
  63. {
  64. $locationId = $this->getRequest()->getParam(LocationInterface::LOCATION_ID);
  65. return preg_replace('/[^\w0-9-_]/', '', $locationId);
  66. }
  67. }