false]); $variable = $this->_initVariable(); $variable->addData($this->getRequest()->getPost('variable')); $result = $variable->validate(); if ($result instanceof \Magento\Framework\Phrase) { $this->messageManager->addError($result->getText()); $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setError(true); $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($response->toArray()); } }