CarrierComponent.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\CarrierInterface;
  7. use Temando\Shipping\Block\Adminhtml\Template\AbstractComponent;
  8. /**
  9. * Temando Carrier Component Layout Block
  10. *
  11. * @package Temando\Shipping\Block
  12. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link http://www.temando.com/
  16. *
  17. * @api
  18. * @deprecated since 1.0.5 | Block data is provided by view model
  19. * @see \Temando\Shipping\ViewModel\Carrier\CarrierEdit
  20. * @see \Temando\Shipping\ViewModel\Carrier\CarrierRegistration
  21. */
  22. class CarrierComponent extends AbstractComponent
  23. {
  24. /**
  25. * Add Back Button.
  26. *
  27. * @return \Magento\Backend\Block\Widget\Container
  28. */
  29. protected function _prepareLayout()
  30. {
  31. $buttonData = [
  32. 'label' => __('Back'),
  33. 'onclick' => sprintf("window.location.href = '%s';", $this->getCarriersPageUrl()),
  34. 'class' => 'back',
  35. 'sort_order' => 10
  36. ];
  37. $this->buttonList->add('back', $buttonData);
  38. return parent::_prepareLayout();
  39. }
  40. /**
  41. * Obtain carriers grid url.
  42. *
  43. * @return string
  44. */
  45. public function getCarriersPageUrl()
  46. {
  47. return $this->getUrl('temando/configuration_carrier/index');
  48. }
  49. /**
  50. * Obtain Add New Carrier url.
  51. *
  52. * @return string
  53. */
  54. public function getCarrierRegistrationPageUrl()
  55. {
  56. return $this->getUrl('temando/configuration_carrier/register');
  57. }
  58. /**
  59. * Obtain Add New Carrier url.
  60. *
  61. * @return string
  62. */
  63. public function getAvailableCarriersPageUrl()
  64. {
  65. return $this->getUrl('temando/configuration_carrier/new');
  66. }
  67. /**
  68. * Obtain the Temando carrier id that is passed from init to edit component.
  69. * Think of it as a GUID rather than a carrier id in the local storage.
  70. *
  71. * @return string The Temando carrier GUID.
  72. */
  73. public function getCarrierConfigurationId()
  74. {
  75. $configurationId = $this->getRequest()->getParam(CarrierInterface::CONFIGURATION_ID);
  76. return preg_replace('/[^\w0-9-_]/', '', $configurationId);
  77. }
  78. /**
  79. * Obtain the Temando carrier integration id.
  80. *
  81. * @return string The Temando carrier integration ID.
  82. */
  83. public function getCarrierIntegrationId()
  84. {
  85. $integrationId = $this->getRequest()->getParam(CarrierInterface::INTEGRATION_ID);
  86. return preg_replace('/[^\w0-9-_]/', '', $integrationId);
  87. }
  88. }