Sharing.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Wishlist customer sharing block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Wishlist\Block\Customer;
  12. use Magento\Captcha\Block\Captcha;
  13. /**
  14. * Class Sharing
  15. *
  16. * @api
  17. * @since 100.0.2
  18. * @package Magento\Wishlist\Block\Customer
  19. */
  20. class Sharing extends \Magento\Framework\View\Element\Template
  21. {
  22. /**
  23. * Entered Data cache
  24. *
  25. * @var array|null
  26. */
  27. protected $_enteredData = null;
  28. /**
  29. * Wishlist configuration
  30. *
  31. * @var \Magento\Wishlist\Model\Config
  32. */
  33. protected $_wishlistConfig;
  34. /**
  35. * @var \Magento\Framework\Session\Generic
  36. */
  37. protected $_wishlistSession;
  38. /**
  39. * @param \Magento\Framework\View\Element\Template\Context $context
  40. * @param \Magento\Wishlist\Model\Config $wishlistConfig
  41. * @param \Magento\Framework\Session\Generic $wishlistSession
  42. * @param array $data
  43. */
  44. public function __construct(
  45. \Magento\Framework\View\Element\Template\Context $context,
  46. \Magento\Wishlist\Model\Config $wishlistConfig,
  47. \Magento\Framework\Session\Generic $wishlistSession,
  48. array $data = []
  49. ) {
  50. $this->_wishlistConfig = $wishlistConfig;
  51. $this->_wishlistSession = $wishlistSession;
  52. parent::__construct($context, $data);
  53. }
  54. /**
  55. * Prepare Global Layout
  56. *
  57. * @return void
  58. */
  59. protected function _prepareLayout()
  60. {
  61. if (!$this->getChildBlock('captcha')) {
  62. $this->addChild(
  63. 'captcha',
  64. Captcha::class,
  65. [
  66. 'cacheable' => false,
  67. 'after' => '-',
  68. 'form_id' => 'share_wishlist_form',
  69. 'image_width' => 230,
  70. 'image_height' => 230
  71. ]
  72. );
  73. }
  74. $this->pageConfig->getTitle()->set(__('Wish List Sharing'));
  75. }
  76. /**
  77. * Retrieve Send Form Action URL
  78. *
  79. * @return string
  80. */
  81. public function getSendUrl()
  82. {
  83. return $this->getUrl('wishlist/index/send');
  84. }
  85. /**
  86. * Retrieve Entered Data by key
  87. *
  88. * @param string $key
  89. * @return string|null
  90. */
  91. public function getEnteredData($key)
  92. {
  93. if ($this->_enteredData === null) {
  94. $this->_enteredData = $this->_wishlistSession->getData('sharing_form', true);
  95. }
  96. if (!$this->_enteredData || !isset($this->_enteredData[$key])) {
  97. return null;
  98. } else {
  99. return $this->escapeHtml($this->_enteredData[$key]);
  100. }
  101. }
  102. /**
  103. * Retrieve back button url
  104. *
  105. * @return string
  106. */
  107. public function getBackUrl()
  108. {
  109. return $this->getUrl('wishlist');
  110. }
  111. /**
  112. * Retrieve number of emails allowed for sharing
  113. *
  114. * @return int
  115. */
  116. public function getEmailSharingLimit()
  117. {
  118. return $this->_wishlistConfig->getSharingEmailLimit();
  119. }
  120. /**
  121. * Retrieve maximum email length allowed for sharing
  122. *
  123. * @return int
  124. */
  125. public function getTextSharingLimit()
  126. {
  127. return $this->_wishlistConfig->getSharingTextLimit();
  128. }
  129. }