This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,79 @@
<?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\Author;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Raw;
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Framework\View\LayoutFactory;
/**
* Class CustomerGrid
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class CustomerGrid extends Action
{
/**
* @var RawFactory
*/
protected $resultRawFactory;
/**
* @var LayoutFactory
*/
protected $layoutFactory;
/**
* @param Context $context
* @param RawFactory $resultRawFactory
* @param LayoutFactory $layoutFactory
*/
public function __construct(
Context $context,
RawFactory $resultRawFactory,
LayoutFactory $layoutFactory
) {
parent::__construct($context);
$this->resultRawFactory = $resultRawFactory;
$this->layoutFactory = $layoutFactory;
}
/**
* Grid Action
*
* @return Raw
*/
public function execute()
{
/** @var Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents(
$this->layoutFactory->create()->createBlock(
\Mageplaza\Blog\Block\Adminhtml\Author\CustomerGrid::class,
'blog.customer.grid'
)->toHtml()
);
}
}
@@ -0,0 +1,99 @@
<?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\Author;
use Exception;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Registry;
use Mageplaza\Blog\Controller\Adminhtml\Author;
use Mageplaza\Blog\Model\AuthorFactory;
use Mageplaza\Blog\Model\PostFactory;
/**
* Class Delete
* @package Mageplaza\Blog\Controller\Adminhtml\Post
*/
class Delete extends Author
{
/**
* @var PostFactory
*/
protected $_postFactory;
/**
* Delete constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param AuthorFactory $authorFactory
* @param PostFactory $postFactory
*/
public function __construct(
Context $context,
Registry $coreRegistry,
AuthorFactory $authorFactory,
PostFactory $postFactory
) {
$this->_postFactory = $postFactory;
parent::__construct($context, $coreRegistry, $authorFactory);
}
/**
* @return Redirect
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if ($id = $this->getRequest()->getParam('id')) {
$post = $this->_postFactory->create();
$postCollectionSize = $post->getCollection()->addFieldToFilter('author_id', ['eq' => $id])->getSize();
if ($postCollectionSize > 0) {
$this->messageManager->addErrorMessage(__('You can not delete this author.'
. ' This is the author of %1 post(s)', $postCollectionSize));
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $id]);
return $resultRedirect;
}
try {
$this->authorFactory->create()
->load($id)
->delete();
$this->messageManager->addSuccessMessage(__('The Author has been deleted.'));
} catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $id]);
return $resultRedirect;
}
} else {
$this->messageManager->addErrorMessage(__('Author to delete was not found.'));
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
}
}
@@ -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\Author;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Mageplaza\Blog\Controller\Adminhtml\Author;
use Mageplaza\Blog\Model\AuthorFactory;
/**
* Class Edit
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class Edit extends Author
{
/**
* @var PageFactory
*/
public $resultPageFactory;
/**
* Edit constructor.
*
* @param Context $context
* @param Registry $registry
* @param AuthorFactory $authorFactory
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
Registry $registry,
AuthorFactory $authorFactory,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $registry, $authorFactory);
}
/**
* @return \Magento\Backend\Model\View\Result\Page|ResponseInterface|ResultInterface|Page
*/
public function execute()
{
/** @var \Mageplaza\Blog\Model\Author $author */
$author = $this->initAuthor();
if (!$author) {
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*');
return $resultRedirect;
}
/** Set entered data if was error when we do save */
$data = $this->_session->getData('mageplaza_blog_author_data', true);
if (!empty($data)) {
$author->addData($data);
}
$this->coreRegistry->register('mageplaza_blog_author', $author);
/** @var \Magento\Backend\Model\View\Result\Page|Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Mageplaza_Blog::author');
$resultPage->getConfig()->getTitle()->set(__('Author Management'));
$resultPage->getConfig()->getTitle()->prepend($author->getId() ? $author->getName() : __('New Author'));
return $resultPage;
}
}
@@ -0,0 +1,65 @@
<?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\Author;
use Magento\Backend\App\Action;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
/**
* Class Index
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class Index extends Action
{
/**
* @var PageFactory
*/
public $_resultPageFactory;
/**
* Index constructor.
*
* @param PageFactory $resultPageFactory
* @param Action\Context $context
*/
public function __construct(
PageFactory $resultPageFactory,
Action\Context $context
) {
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* @return ResponseInterface|ResultInterface|Page
*/
public function execute()
{
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__('Authors'));
return $resultPage;
}
}
@@ -0,0 +1,129 @@
<?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\Author;
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\Author;
use Mageplaza\Blog\Model\AuthorFactory;
use Mageplaza\Blog\Model\Post;
use RuntimeException;
/**
* Class InlineEdit
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class InlineEdit extends Action
{
/**
* JSON Factory
*
* @var JsonFactory
*/
public $jsonFactory;
/**
* Author Factory
*
* @var AuthorFactory
*/
public $authorFactory;
/**
* InlineEdit constructor.
*
* @param Context $context
* @param JsonFactory $jsonFactory
* @param AuthorFactory $postFactory
*/
public function __construct(
Context $context,
JsonFactory $jsonFactory,
AuthorFactory $postFactory
) {
$this->jsonFactory = $jsonFactory;
$this->authorFactory = $postFactory;
parent::__construct($context);
}
/**
* @return ResultInterface
*/
public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
$authorItems = $this->getRequest()->getParam('items', []);
if (!(!empty($authorItems) && $this->getRequest()->getParam('isAjax'))) {
return $resultJson->setData([
'messages' => [__('Please correct the data sent.')],
'error' => true,
]);
}
$key = array_keys($authorItems);
$authorId = !empty($key) ? (int)$key[0] : '';
/** @var Post $post */
$author = $this->authorFactory->create()->load($authorId);
try {
$authorData = $authorItems[$authorId];
$author->addData($authorData);
$author->save();
} catch (LocalizedException $e) {
$messages[] = $this->getErrorWithPostId($post, $e->getMessage());
$error = true;
} catch (RuntimeException $e) {
$messages[] = $this->getErrorWithPostId($post, $e->getMessage());
$error = true;
} catch (Exception $e) {
$messages[] = $this->getErrorWithPostId(
$author,
__('Something went wrong while saving the Post.')
);
$error = true;
}
return $resultJson->setData([
'messages' => $messages,
'error' => $error
]);
}
/**
* @param Author $author
* @param $errorText
*
* @return string
*/
public function getErrorWithPostId(Author $author, $errorText)
{
return '[Post ID: ' . $author->getId() . '] ' . $errorText;
}
}
@@ -0,0 +1,107 @@
<?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\Author;
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\Author\CollectionFactory;
/**
* Class MassDelete
* @package Mageplaza\Blog\Controller\Adminhtml\Post
*/
class MassDelete extends Action
{
/**
* Mass Action Filter
*
* @var Filter
*/
public $filter;
/**
* Collection Factory
*
* @var CollectionFactory
*/
public $collectionFactory;
/**
* 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 Redirect|ResponseInterface|ResultInterface
* @throws LocalizedException
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$authorRemove = 0;
foreach ($collection->getItems() as $author) {
if ($author->hasPost()) {
$this->messageManager->addWarningMessage(__('One of the authors has post. You can not delete this one.'));
} else {
try {
$author->delete();
$authorRemove++;
} catch (Exception $e) {
$this->_getSession()->addException(
$e,
__('Something went wrong while updating status for %1.', $author->getName())
);
}
}
}
if ($authorRemove) {
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been removed.', $authorRemove));
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
}
@@ -0,0 +1,108 @@
<?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\Author;
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\Author\CollectionFactory;
/**
* Class MassStatus
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class MassStatus extends Action
{
/**
* Mass Action Filter
*
* @var Filter
*/
public $filter;
/**
* Collection Factory
*
* @var CollectionFactory
*/
public $collectionFactory;
/**
* constructor
*
* @param Filter $filter
* @param CollectionFactory $collectionFactory
* @param Context $context
*/
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());
$status = (int)$this->getRequest()->getParam('status');
$authorUpdated = 0;
foreach ($collection as $post) {
try {
$post->setStatus($status)
->save();
$authorUpdated++;
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException(
$e,
__('Something went wrong while updating status for %1.', $post->getName())
);
}
}
if ($authorUpdated) {
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $authorUpdated));
}
/** @var Redirect $resultRedirect */
$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\Author;
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,70 @@
<?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\Author;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\Layout;
use Magento\Framework\View\Result\LayoutFactory;
use Mageplaza\Blog\Controller\Adminhtml\Author;
use Mageplaza\Blog\Model\AuthorFactory;
/**
* Class Posts
* @package Mageplaza\Blog\Controller\Adminhtml\Tag
*/
class Posts extends Author
{
/**
* @var LayoutFactory
*/
public $resultLayoutFactory;
/**
* Posts constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param LayoutFactory $resultLayoutFactory
* @param AuthorFactory $authorFactory
*/
public function __construct(
Context $context,
Registry $coreRegistry,
LayoutFactory $resultLayoutFactory,
AuthorFactory $authorFactory
) {
$this->resultLayoutFactory = $resultLayoutFactory;
parent::__construct($context, $coreRegistry, $authorFactory);
}
/**
* @return Layout
*/
public function execute()
{
$this->initAuthor(true);
return $this->resultLayoutFactory->create();
}
}
@@ -0,0 +1,30 @@
<?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\Author;
/**
* Class PostsGrid
* @package Mageplaza\Blog\Controller\Adminhtml\Tag
*/
class PostsGrid extends Posts
{
}
@@ -0,0 +1,158 @@
<?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\Author;
use Exception;
use Magento\Backend\App\Action\Context;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Mageplaza\Blog\Controller\Adminhtml\Author;
use Mageplaza\Blog\Helper\Image;
use Mageplaza\Blog\Model\AuthorFactory;
use RuntimeException;
/**
* Class Save
* @package Mageplaza\Blog\Controller\Adminhtml\Author
*/
class Save extends Author
{
/**
* @var Image
*/
protected $imageHelper;
/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
/**
* Save constructor.
*
* @param Context $context
* @param Registry $registry
* @param AuthorFactory $authorFactory
* @param CustomerRepositoryInterface $customerRepository
* @param Image $imageHelper
*/
public function __construct(
Context $context,
Registry $registry,
AuthorFactory $authorFactory,
CustomerRepositoryInterface $customerRepository,
Image $imageHelper
) {
$this->imageHelper = $imageHelper;
$this->customerRepository = $customerRepository;
parent::__construct($context, $registry, $authorFactory);
}
/**
* @return ResponseInterface|Redirect|ResultInterface
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if ($data = $this->getRequest()->getPost('author')) {
/** @var \Mageplaza\Blog\Model\Author $author */
$author = $this->initAuthor();
$this->prepareData($author, $data);
$this->_eventManager->dispatch(
'mageplaza_blog_author_prepare_save',
['author' => $author, 'request' => $this->getRequest()]
);
try {
$author->save();
$this->messageManager->addSuccessMessage(__('The Author has been saved.'));
$this->_getSession()->setData('mageplaza_blog_author_data', false);
if ($this->getRequest()->getParam('back')) {
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $author->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 Author.'));
}
$this->_getSession()->setData('mageplaza_blog_author_data', $data);
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $author->getId(), '_current' => true]);
return $resultRedirect;
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
}
/**
* @param $author
* @param $data
*
* @return $this
*/
public function prepareData($author, $data)
{
// upload image
if (!$this->getRequest()->getParam('image')) {
try {
$this->imageHelper->uploadImage($data, 'image', Image::TEMPLATE_MEDIA_TYPE_AUTH, $author->getImage());
} catch (Exception $exception) {
$data['image'] = isset($data['image']['value']) ? $data['image']['value'] : '';
}
}
if ($this->getRequest()->getParam('image') && isset($this->getRequest()->getParam('image')['delete'])) {
$data['image'] = '';
}
// set data
if (!empty($data)) {
if (!empty($data['customer_id'])) {
try {
$data['email'] = $this->customerRepository->getById($data['customer_id'])->getEmail();
} catch (Exception $e) {
$data['email'] = '';
}
}
$author->addData($data);
}
return $this;
}
}