View.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Adminhtml\Billing\Agreement;
  7. /**
  8. * Adminhtml billing agreement view
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class View extends \Magento\Backend\Block\Widget\Form\Container
  14. {
  15. /**
  16. * Core registry
  17. *
  18. * @var \Magento\Framework\Registry
  19. */
  20. protected $_coreRegistry = null;
  21. /**
  22. * @param \Magento\Backend\Block\Widget\Context $context
  23. * @param \Magento\Framework\Registry $registry
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Widget\Context $context,
  28. \Magento\Framework\Registry $registry,
  29. array $data = []
  30. ) {
  31. $this->_coreRegistry = $registry;
  32. parent::__construct($context, $data);
  33. }
  34. /**
  35. * Initialize view container
  36. *
  37. * @return void
  38. */
  39. protected function _construct()
  40. {
  41. $this->_objectId = 'agreement';
  42. $this->_controller = 'adminhtml_billing_agreement';
  43. $this->_mode = 'view';
  44. $this->_blockGroup = 'Magento_Paypal';
  45. parent::_construct();
  46. if (!$this->_isAllowed('Magento_Paypal::actions_manage')) {
  47. $this->buttonList->remove('delete');
  48. }
  49. $this->buttonList->remove('reset');
  50. $this->buttonList->remove('save');
  51. $this->setId('billing_agreement_view');
  52. $this->buttonList->add(
  53. 'back',
  54. [
  55. 'label' => __('Back'),
  56. 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
  57. 'class' => 'back'
  58. ],
  59. -1
  60. );
  61. $agreement = $this->_getBillingAgreement();
  62. if ($agreement && $agreement->canCancel() && $this->_isAllowed('Magento_Paypal::actions_manage')) {
  63. $confirmText = __('Are you sure you want to do this?');
  64. $this->buttonList->add(
  65. 'cancel',
  66. [
  67. 'label' => __('Cancel'),
  68. 'onclick' => "confirmSetLocation(" . "'{$confirmText}', '{$this->_getCancelUrl()}'" . ")",
  69. 'class' => 'cancel'
  70. ],
  71. -1
  72. );
  73. }
  74. }
  75. /**
  76. * Retrieve header text
  77. *
  78. * @return \Magento\Framework\Phrase
  79. */
  80. public function getHeaderText()
  81. {
  82. return __('Billing Agreement #%1', $this->_getBillingAgreement()->getReferenceId());
  83. }
  84. /**
  85. * Retrieve cancel billing agreement url
  86. *
  87. * @return string
  88. */
  89. protected function _getCancelUrl()
  90. {
  91. return $this->getUrl('*/*/cancel', ['agreement' => $this->_getBillingAgreement()->getAgreementId()]);
  92. }
  93. /**
  94. * Retrieve billing agreement model
  95. *
  96. * @return \Magento\Paypal\Model\Billing\Agreement
  97. */
  98. protected function _getBillingAgreement()
  99. {
  100. return $this->_coreRegistry->registry('current_billing_agreement');
  101. }
  102. /**
  103. * Check current user permissions for specified action
  104. *
  105. * @param string $resourceId
  106. * @return bool
  107. */
  108. protected function _isAllowed($resourceId)
  109. {
  110. return $this->_authorization->isAllowed($resourceId);
  111. }
  112. }