WebhookUrl.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Signifyd\Block\Adminhtml\System\Config\Field;
  7. use Magento\Framework\Data\Form\Element\AbstractElement;
  8. use Magento\Config\Block\System\Config\Form\Field;
  9. use Magento\Store\Model\ScopeInterface;
  10. use Magento\Store\Model\Store;
  11. /**
  12. * Input field transformed to text node with link to store Signifyd webhooks controller.
  13. */
  14. class WebhookUrl extends Field
  15. {
  16. /**
  17. * @inheritdoc
  18. */
  19. protected function _getElementHtml(AbstractElement $element)
  20. {
  21. $url = '';
  22. $originalData = $element->getOriginalData();
  23. if (!empty($originalData['handler_url'])) {
  24. $url = $this->getStoreUrl();
  25. $url .= $originalData['handler_url'];
  26. }
  27. return '<p class="webhook-url">' . $this->escapeHtml($url) . '</p>';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. protected function _isInheritCheckboxRequired(AbstractElement $element)
  33. {
  34. return false;
  35. }
  36. /**
  37. * Return base store URL.
  38. *
  39. * @return string
  40. */
  41. private function getStoreUrl()
  42. {
  43. $website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'));
  44. $isSecure = $this->_scopeConfig->isSetFlag(
  45. Store::XML_PATH_SECURE_IN_FRONTEND,
  46. ScopeInterface::SCOPE_WEBSITE,
  47. $website->getCode()
  48. );
  49. $configPath = $isSecure ? Store::XML_PATH_SECURE_BASE_LINK_URL : Store::XML_PATH_UNSECURE_BASE_LINK_URL;
  50. return $this->_scopeConfig->getValue($configPath, ScopeInterface::SCOPE_WEBSITE, $website->getCode());
  51. }
  52. }