resultRedirectFactory->create(); if ($data = $this->getRequest()->getPost('comment')) { /** @var \Mageplaza\Blog\Model\Comment $post */ $comment = $this->initComment(); $this->prepareData($comment, $data); $this->_eventManager->dispatch( 'mageplaza_blog_comment_prepare_save', ['comment' => $comment, 'request' => $this->getRequest()] ); try { $comment->save(); $this->_eventManager->dispatch('blog_post_comment', ['comment_data' => $comment]); $this->messageManager->addSuccessMessage(__('The comment has been saved.')); $this->_getSession()->setData('mageplaza_blog_comment_data', false); if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $comment->getId(), '_current' => true]); } else { $resultRedirect->setPath('mageplaza_blog/*/'); } return $resultRedirect; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (RuntimeException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Comment.')); } $this->_getSession()->setData('mageplaza_blog_comment_data', $data); $resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $comment->getId(), '_current' => true]); return $resultRedirect; } $resultRedirect->setPath('mageplaza_blog/*/'); return $resultRedirect; } /** * @param $comment * @param array $data * * @return $this */ protected function prepareData($comment, $data = []) { $comment->addData($data); return $this; } }