Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Index.php
Go to the documentation of this file.
1 <?php
10 
11 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
13 
14 class Index extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
15 {
19  protected $captchaHelper;
20 
24  protected $serializer;
25 
32  public function __construct(
33  Context $context,
34  \Magento\Captcha\Helper\Data $captchaHelper,
35  \Magento\Framework\Serialize\Serializer\Json $serializer = null
36  ) {
37  $this->captchaHelper = $captchaHelper;
39  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
40  parent::__construct($context);
41  }
42 
46  public function execute()
47  {
48  $formId = $this->_request->getPost('formId');
49  if (null === $formId) {
50  $params = [];
51  $content = $this->_request->getContent();
52  if ($content) {
53  $params = $this->serializer->unserialize($content);
54  }
55  $formId = isset($params['formId']) ? $params['formId'] : null;
56  }
57  $captchaModel = $this->captchaHelper->getCaptcha($formId);
58  $captchaModel->generate();
59 
60  $block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
61  $block->setFormId($formId)->setIsAjax(true)->toHtml();
62  $this->_response->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
63  $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
64  }
65 }
$block
Definition: block.php:8
__construct(Context $context, \Magento\Captcha\Helper\Data $captchaHelper, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
Definition: Index.php:32
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18