init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
/**
|
||||
* Class Delete
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class Delete extends Comment
|
||||
{
|
||||
/**
|
||||
* @return Redirect
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
if ($id = $this->getRequest()->getParam('id')) {
|
||||
try {
|
||||
$this->commentFactory->create()
|
||||
->load($id)
|
||||
->delete();
|
||||
|
||||
$this->messageManager->addSuccessMessage(__('The Comment has been deleted.'));
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $id]);
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage(__('Comment to delete was not found.'));
|
||||
}
|
||||
|
||||
$resultRedirect->setPath('mageplaza_blog/*/');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
use Mageplaza\Blog\Model\CommentFactory;
|
||||
|
||||
/**
|
||||
* Class Edit
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class Edit extends Comment
|
||||
{
|
||||
/**
|
||||
* Page factory
|
||||
*
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Edit constructor.
|
||||
*
|
||||
* @param PageFactory $pageFactory
|
||||
* @param CommentFactory $commentFactory
|
||||
* @param Registry $coreRegistry
|
||||
* @param Context $context
|
||||
*/
|
||||
public function __construct(
|
||||
PageFactory $pageFactory,
|
||||
CommentFactory $commentFactory,
|
||||
Registry $coreRegistry,
|
||||
Context $context
|
||||
) {
|
||||
$this->resultPageFactory = $pageFactory;
|
||||
|
||||
parent::__construct($commentFactory, $coreRegistry, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Backend\Model\View\Result\Page|Redirect|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Mageplaza\Blog\Model\Comment $comment */
|
||||
$comment = $this->initComment();
|
||||
|
||||
if (!$comment) {
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$resultRedirect->setPath('*');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
$data = $this->_session->getData('mageplaza_blog_comment_data', true);
|
||||
|
||||
if (!empty($data)) {
|
||||
$comment->setData($data);
|
||||
}
|
||||
|
||||
$this->coreRegistry->register('mageplaza_blog_comment', $comment);
|
||||
|
||||
/** @var \Magento\Backend\Model\View\Result\Page|Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->setActiveMenu('Mageplaza_Blog::comment');
|
||||
|
||||
$title = __('Edit Comment');
|
||||
$resultPage->getConfig()->getTitle()->prepend($title);
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
/**
|
||||
* Class Index
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class Index extends Action
|
||||
{
|
||||
/**
|
||||
* Page result factory
|
||||
*
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Index constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute the action
|
||||
*
|
||||
* @return \Magento\Backend\Model\View\Result\Page|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Comments'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\Result\Json;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Mageplaza\Blog\Model\Comment;
|
||||
use Mageplaza\Blog\Model\CommentFactory;
|
||||
use Mageplaza\Blog\Model\Post;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class InlineEdit
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class InlineEdit extends Action
|
||||
{
|
||||
/**
|
||||
* JSON Factory
|
||||
*
|
||||
* @var JsonFactory
|
||||
*/
|
||||
public $jsonFactory;
|
||||
|
||||
/**
|
||||
* Post Factory
|
||||
*
|
||||
* @var CommentFactory
|
||||
*/
|
||||
public $commentFactory;
|
||||
|
||||
/**
|
||||
* InlineEdit constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param JsonFactory $jsonFactory
|
||||
* @param CommentFactory $commentFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
JsonFactory $jsonFactory,
|
||||
CommentFactory $commentFactory
|
||||
) {
|
||||
$this->jsonFactory = $jsonFactory;
|
||||
$this->commentFactory = $commentFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Json $resultJson */
|
||||
$resultJson = $this->jsonFactory->create();
|
||||
$error = false;
|
||||
$messages = [];
|
||||
$commentItems = $this->getRequest()->getParam('items', []);
|
||||
|
||||
if (!($this->getRequest()->getParam('isAjax') && !empty($commentItems))) {
|
||||
return $resultJson->setData([
|
||||
'messages' => [
|
||||
__('Please correct the data sent.')
|
||||
],
|
||||
'error' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$key = array_keys($commentItems);
|
||||
$commentId = !empty($key) ? (int)$key[0] : '';
|
||||
|
||||
/** @var Post $post */
|
||||
$comment = $this->commentFactory->create()->load($commentId);
|
||||
try {
|
||||
$commentData = $commentItems[$commentId];
|
||||
$comment->addData($commentData);
|
||||
$comment->save();
|
||||
} catch (LocalizedException $e) {
|
||||
$messages[] = $this->getErrorWithCommentId($comment, $e->getMessage());
|
||||
$error = true;
|
||||
} catch (RuntimeException $e) {
|
||||
$messages[] = $this->getErrorWithCommentId($comment, $e->getMessage());
|
||||
$error = true;
|
||||
} catch (Exception $e) {
|
||||
$messages[] = $this->getErrorWithCommentId(
|
||||
$comment,
|
||||
__('Something went wrong while saving the Comment.')
|
||||
);
|
||||
$error = true;
|
||||
}
|
||||
|
||||
return $resultJson->setData([
|
||||
'messages' => $messages,
|
||||
'error' => $error
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
* @param $errorText
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorWithCommentId(Comment $comment, $errorText)
|
||||
{
|
||||
return '[Comment ID: ' . $comment->getId() . '] ' . $errorText;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Mageplaza\Blog\Model\ResourceModel\Comment\CollectionFactory;
|
||||
|
||||
/**
|
||||
* Class MassDelete
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class MassDelete extends Action
|
||||
{
|
||||
/**
|
||||
* Mass Action Filter
|
||||
*
|
||||
* @var Filter
|
||||
*/
|
||||
public $filter;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
public $collectionFactory;
|
||||
|
||||
/**
|
||||
* MassDelete constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param Filter $filter
|
||||
* @param CollectionFactory $collectionFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
CollectionFactory $collectionFactory
|
||||
) {
|
||||
$this->filter = $filter;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|ResponseInterface|ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
|
||||
try {
|
||||
$count = 0;
|
||||
foreach ($collection as $item) {
|
||||
$item->delete();
|
||||
$count++;
|
||||
}
|
||||
$this->messageManager->addSuccessMessage(__('Total of %1 comments has been deleted.', $count));
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addErrorMessage(__('Something wrong when delete Comments.'));
|
||||
}
|
||||
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
|
||||
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Mageplaza\Blog\Model\ResourceModel\Comment\CollectionFactory;
|
||||
|
||||
/**
|
||||
* Class MassStatus
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class MassStatus extends Action
|
||||
{
|
||||
/**
|
||||
* Mass Action Filter
|
||||
*
|
||||
* @var Filter
|
||||
*/
|
||||
public $filter;
|
||||
|
||||
/**
|
||||
* Collection Factory
|
||||
*
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
public $collectionFactory;
|
||||
|
||||
/**
|
||||
* MassStatus constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param Filter $filter
|
||||
* @param CollectionFactory $collectionFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
CollectionFactory $collectionFactory
|
||||
) {
|
||||
$this->filter = $filter;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return ResponseInterface|ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$commentUpdated = 0;
|
||||
$status = (int)$this->getRequest()->getParam('status');
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
|
||||
foreach ($collection as $comment) {
|
||||
try {
|
||||
$comment->setStatus($status)->save();
|
||||
$this->_eventManager->dispatch('blog_post_comment', ['comment_data' => $comment]);
|
||||
$commentUpdated++;
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->_getSession()->addException($e, __('Something went wrong while updating status'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($commentUpdated) {
|
||||
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $commentUpdated));
|
||||
}
|
||||
|
||||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
|
||||
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Forward;
|
||||
use Magento\Backend\Model\View\Result\ForwardFactory;
|
||||
|
||||
/**
|
||||
* Class NewAction
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Post
|
||||
*/
|
||||
class NewAction extends Action
|
||||
{
|
||||
/**
|
||||
* Redirect result factory
|
||||
*
|
||||
* @var ForwardFactory
|
||||
*/
|
||||
public $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
* @param Context $context
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
ForwardFactory $resultForwardFactory
|
||||
) {
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* forward to edit
|
||||
*
|
||||
* @return Forward
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
$resultForward->forward('edit');
|
||||
|
||||
return $resultForward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Mageplaza\Blog\Controller\Adminhtml\Comment;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class Save
|
||||
* @package Mageplaza\Blog\Controller\Adminhtml\Comment
|
||||
*/
|
||||
class Save extends Comment
|
||||
{
|
||||
/**
|
||||
* @return Redirect
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user