RegisterLink.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Context;
  8. /**
  9. * Customer register link
  10. *
  11. * @api
  12. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  13. * @since 100.0.2
  14. */
  15. class RegisterLink extends \Magento\Framework\View\Element\Html\Link
  16. {
  17. /**
  18. * Customer session
  19. *
  20. * @var \Magento\Framework\App\Http\Context
  21. */
  22. protected $httpContext;
  23. /**
  24. * @var \Magento\Customer\Model\Registration
  25. */
  26. protected $_registration;
  27. /**
  28. * @var \Magento\Customer\Model\Url
  29. */
  30. protected $_customerUrl;
  31. /**
  32. * @param \Magento\Framework\View\Element\Template\Context $context
  33. * @param \Magento\Framework\App\Http\Context $httpContext
  34. * @param \Magento\Customer\Model\Registration $registration
  35. * @param \Magento\Customer\Model\Url $customerUrl
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Framework\View\Element\Template\Context $context,
  40. \Magento\Framework\App\Http\Context $httpContext,
  41. \Magento\Customer\Model\Registration $registration,
  42. \Magento\Customer\Model\Url $customerUrl,
  43. array $data = []
  44. ) {
  45. parent::__construct($context, $data);
  46. $this->httpContext = $httpContext;
  47. $this->_registration = $registration;
  48. $this->_customerUrl = $customerUrl;
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function getHref()
  54. {
  55. return $this->_customerUrl->getRegisterUrl();
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. protected function _toHtml()
  61. {
  62. if (!$this->_registration->isAllowed()
  63. || $this->httpContext->getValue(Context::CONTEXT_AUTH)
  64. ) {
  65. return '';
  66. }
  67. return parent::_toHtml();
  68. }
  69. }