Link.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order;
  7. /**
  8. * Sales order link
  9. *
  10. * @api
  11. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  12. * @since 100.0.2
  13. */
  14. class Link extends \Magento\Framework\View\Element\Html\Link\Current
  15. {
  16. /**
  17. * @var \Magento\Framework\Registry
  18. */
  19. protected $_registry;
  20. /**
  21. * @param \Magento\Framework\View\Element\Template\Context $context
  22. * @param \Magento\Framework\App\DefaultPathInterface $defaultPath
  23. * @param \Magento\Framework\Registry $registry
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Framework\View\Element\Template\Context $context,
  28. \Magento\Framework\App\DefaultPathInterface $defaultPath,
  29. \Magento\Framework\Registry $registry,
  30. array $data = []
  31. ) {
  32. parent::__construct($context, $defaultPath, $data);
  33. $this->_registry = $registry;
  34. }
  35. /**
  36. * Retrieve current order model instance
  37. *
  38. * @return \Magento\Sales\Model\Order
  39. */
  40. private function getOrder()
  41. {
  42. return $this->_registry->registry('current_order');
  43. }
  44. /**
  45. * @inheritdoc
  46. *
  47. * @return string
  48. */
  49. public function getHref()
  50. {
  51. return $this->getUrl($this->getPath(), ['order_id' => $this->getOrder()->getId()]);
  52. }
  53. /**
  54. * @inheritdoc
  55. *
  56. * @return string
  57. */
  58. protected function _toHtml()
  59. {
  60. if ($this->hasKey()
  61. && method_exists($this->getOrder(), 'has' . $this->getKey())
  62. && !$this->getOrder()->{'has' . $this->getKey()}()
  63. ) {
  64. return '';
  65. }
  66. return parent::_toHtml();
  67. }
  68. }