AuthenticationPopup.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Account;
  7. use Magento\Customer\Model\Form;
  8. use Magento\Store\Model\ScopeInterface;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class AuthenticationPopup extends \Magento\Framework\View\Element\Template
  14. {
  15. /**
  16. * @var array
  17. */
  18. protected $jsLayout;
  19. /**
  20. * @var \Magento\Framework\Serialize\Serializer\Json
  21. */
  22. private $serializer;
  23. /**
  24. * @param \Magento\Framework\View\Element\Template\Context $context
  25. * @param array $data
  26. * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
  27. * @throws \RuntimeException
  28. */
  29. public function __construct(
  30. \Magento\Framework\View\Element\Template\Context $context,
  31. array $data = [],
  32. \Magento\Framework\Serialize\Serializer\Json $serializer = null
  33. ) {
  34. parent::__construct($context, $data);
  35. $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
  36. $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
  37. ->get(\Magento\Framework\Serialize\Serializer\Json::class);
  38. }
  39. /**
  40. * @return string
  41. */
  42. public function getJsLayout()
  43. {
  44. return $this->serializer->serialize($this->jsLayout);
  45. }
  46. /**
  47. * Returns popup config
  48. *
  49. * @return array
  50. */
  51. public function getConfig()
  52. {
  53. return [
  54. 'autocomplete' => $this->escapeHtml($this->isAutocompleteEnabled()),
  55. 'customerRegisterUrl' => $this->escapeUrl($this->getCustomerRegisterUrlUrl()),
  56. 'customerForgotPasswordUrl' => $this->escapeUrl($this->getCustomerForgotPasswordUrl()),
  57. 'baseUrl' => $this->escapeUrl($this->getBaseUrl())
  58. ];
  59. }
  60. /**
  61. * Returns popup config in JSON format.
  62. *
  63. * Added in scope of https://github.com/magento/magento2/pull/8617
  64. *
  65. * @return bool|string
  66. * @since 101.0.0
  67. */
  68. public function getSerializedConfig()
  69. {
  70. return $this->serializer->serialize($this->getConfig());
  71. }
  72. /**
  73. * Is autocomplete enabled for storefront
  74. *
  75. * @return string
  76. */
  77. private function isAutocompleteEnabled()
  78. {
  79. return $this->_scopeConfig->getValue(
  80. Form::XML_PATH_ENABLE_AUTOCOMPLETE,
  81. ScopeInterface::SCOPE_STORE
  82. ) ? 'on' : 'off';
  83. }
  84. /**
  85. * Return base url.
  86. *
  87. * @return string
  88. */
  89. public function getBaseUrl()
  90. {
  91. return $this->_storeManager->getStore()->getBaseUrl();
  92. }
  93. /**
  94. * Get customer register url
  95. *
  96. * @return string
  97. */
  98. public function getCustomerRegisterUrlUrl()
  99. {
  100. return $this->getUrl('customer/account/create');
  101. }
  102. /**
  103. * Get customer forgot password url
  104. *
  105. * @return string
  106. */
  107. public function getCustomerForgotPasswordUrl()
  108. {
  109. return $this->getUrl('customer/account/forgotpassword');
  110. }
  111. }