Captcha.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Captcha block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Captcha\Block;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Captcha extends \Magento\Framework\View\Element\Template
  17. {
  18. /**
  19. * Captcha data
  20. *
  21. * @var \Magento\Captcha\Helper\Data
  22. */
  23. protected $_captchaData = null;
  24. /**
  25. * @param \Magento\Framework\View\Element\Template\Context $context
  26. * @param \Magento\Captcha\Helper\Data $captchaData
  27. * @param array $data
  28. */
  29. public function __construct(
  30. \Magento\Framework\View\Element\Template\Context $context,
  31. \Magento\Captcha\Helper\Data $captchaData,
  32. array $data = []
  33. ) {
  34. $this->_captchaData = $captchaData;
  35. parent::__construct($context, $data);
  36. $this->_isScopePrivate = true;
  37. }
  38. /**
  39. * Renders captcha HTML (if required)
  40. *
  41. * @return string
  42. */
  43. protected function _toHtml()
  44. {
  45. $blockPath = $this->_captchaData->getCaptcha($this->getFormId())->getBlockName();
  46. $block = $this->getLayout()->createBlock($blockPath);
  47. $block->setData($this->getData());
  48. return $block->toHtml();
  49. }
  50. }