View.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Comments;
  7. /**
  8. * Invoice view comments form
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class View extends \Magento\Backend\Block\Template
  15. {
  16. /**
  17. * Sales data
  18. *
  19. * @var \Magento\Sales\Helper\Data
  20. */
  21. protected $_salesData = null;
  22. /**
  23. * @var \Magento\Sales\Helper\Admin
  24. */
  25. private $adminHelper;
  26. /**
  27. * @param \Magento\Backend\Block\Template\Context $context
  28. * @param \Magento\Sales\Helper\Data $salesData
  29. * @param \Magento\Sales\Helper\Admin $adminHelper
  30. * @param array $data
  31. */
  32. public function __construct(
  33. \Magento\Backend\Block\Template\Context $context,
  34. \Magento\Sales\Helper\Data $salesData,
  35. \Magento\Sales\Helper\Admin $adminHelper,
  36. array $data = []
  37. ) {
  38. $this->_salesData = $salesData;
  39. parent::__construct($context, $data);
  40. $this->adminHelper = $adminHelper;
  41. }
  42. /**
  43. * Retrieve required options from parent
  44. *
  45. * @return void
  46. * @throws \Magento\Framework\Exception\LocalizedException
  47. */
  48. protected function _beforeToHtml()
  49. {
  50. if (!$this->getParentBlock()) {
  51. throw new \Magento\Framework\Exception\LocalizedException(
  52. __('Please correct the parent block for this block.')
  53. );
  54. }
  55. $this->setEntity($this->getParentBlock()->getSource());
  56. parent::_beforeToHtml();
  57. }
  58. /**
  59. * Preparing global layout
  60. *
  61. * @return $this
  62. */
  63. protected function _prepareLayout()
  64. {
  65. $this->addChild(
  66. 'submit_button',
  67. \Magento\Backend\Block\Widget\Button::class,
  68. ['id' => 'submit_comment_button', 'label' => __('Submit Comment'), 'class' => 'action-secondary save']
  69. );
  70. return parent::_prepareLayout();
  71. }
  72. /**
  73. * Get submit url
  74. *
  75. * @return string|true
  76. */
  77. public function getSubmitUrl()
  78. {
  79. return $this->getUrl('*/*/addComment', ['id' => $this->getEntity()->getId()]);
  80. }
  81. /**
  82. * @return bool
  83. */
  84. public function canSendCommentEmail()
  85. {
  86. switch ($this->getParentType()) {
  87. case 'invoice':
  88. return $this->_salesData->canSendInvoiceCommentEmail(
  89. $this->getEntity()->getOrder()->getStore()->getId()
  90. );
  91. case 'shipment':
  92. return $this->_salesData->canSendShipmentCommentEmail(
  93. $this->getEntity()->getOrder()->getStore()->getId()
  94. );
  95. case 'creditmemo':
  96. return $this->_salesData->canSendCreditmemoCommentEmail(
  97. $this->getEntity()->getOrder()->getStore()->getId()
  98. );
  99. }
  100. return true;
  101. }
  102. /**
  103. * Replace links in string
  104. *
  105. * @param array|string $data
  106. * @param null|array $allowedTags
  107. * @return string
  108. */
  109. public function escapeHtml($data, $allowedTags = null)
  110. {
  111. return $this->adminHelper->escapeHtmlWithLinks($data, $allowedTags);
  112. }
  113. }