View.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Adminhtml\Order\Tracking;
  7. /**
  8. * Shipment tracking control form
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class View extends \Magento\Shipping\Block\Adminhtml\Order\Tracking
  14. {
  15. /**
  16. * @var \Magento\Shipping\Model\CarrierFactory
  17. */
  18. protected $_carrierFactory;
  19. /**
  20. * @param \Magento\Backend\Block\Template\Context $context
  21. * @param \Magento\Shipping\Model\Config $shippingConfig
  22. * @param \Magento\Framework\Registry $registry
  23. * @param \Magento\Shipping\Model\CarrierFactory $carrierFactory
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Template\Context $context,
  28. \Magento\Shipping\Model\Config $shippingConfig,
  29. \Magento\Framework\Registry $registry,
  30. \Magento\Shipping\Model\CarrierFactory $carrierFactory,
  31. array $data = []
  32. ) {
  33. parent::__construct($context, $shippingConfig, $registry, $data);
  34. $this->_carrierFactory = $carrierFactory;
  35. }
  36. /**
  37. * Prepares layout of block
  38. *
  39. * @return void
  40. */
  41. protected function _prepareLayout()
  42. {
  43. $onclick = "submitAndReloadArea($('shipment_tracking_info').parentNode, '" . $this->getSubmitUrl() . "')";
  44. $this->addChild(
  45. 'save_button',
  46. \Magento\Backend\Block\Widget\Button::class,
  47. ['label' => __('Add'), 'class' => 'save', 'onclick' => $onclick]
  48. );
  49. }
  50. /**
  51. * Retrieve save url
  52. *
  53. * @return string
  54. */
  55. public function getSubmitUrl()
  56. {
  57. return $this->getUrl('adminhtml/*/addTrack/', ['shipment_id' => $this->getShipment()->getId()]);
  58. }
  59. /**
  60. * Retrieve save button html
  61. *
  62. * @return string
  63. */
  64. public function getSaveButtonHtml()
  65. {
  66. return $this->getChildHtml('save_button');
  67. }
  68. /**
  69. * Retrieve remove url
  70. *
  71. * @param \Magento\Sales\Model\Order\Shipment\Track $track
  72. * @return string
  73. */
  74. public function getRemoveUrl($track)
  75. {
  76. return $this->getUrl(
  77. 'adminhtml/*/removeTrack/',
  78. ['shipment_id' => $this->getShipment()->getId(), 'track_id' => $track->getId()]
  79. );
  80. }
  81. /**
  82. * @param string $code
  83. * @return \Magento\Framework\Phrase|string|bool
  84. */
  85. public function getCarrierTitle($code)
  86. {
  87. $carrier = $this->_carrierFactory->create($code);
  88. return $carrier ? $carrier->getConfigData('title') : __('Custom Value');
  89. }
  90. }