_helperBlog = $helperData; $this->resultPageFactory = $resultPageFactory; $this->resultForwardFactory = $resultForwardFactory; $this->customerSession = $customerSession; $this->imageHelper = $imageHelper; $this->author = $authorFactory; parent::__construct($context); } /** * @return ResponseInterface|Redirect|ResultInterface */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getParams(); $this->_helperBlog->setCustomerContextId(); if (!$this->_helperBlog->isEnabledAuthor()) { $resultRedirect->setPath('customer/account'); return $resultRedirect; } if ($data) { if ($this->_helperBlog->isAuthor()) { $data = $this->prepareData($data); $author = $this->author->create()->addData($data); $notify = __('Register Successful'); } else { $author = $this->_helperBlog->getCurrentAuthor(); $data = $this->prepareData($data, $author); $author->addData($data); $notify = __('Author Edited Successful'); } try { $author->save(); $resultRedirect->setPath('mpblog/*/information'); $this->messageManager->addSuccessMessage($notify); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Author.')); $resultRedirect->setPath('mpblog/*/signup'); } } return $resultRedirect; } /** * @param $data * @param null $author * * @return mixed */ public function prepareData($data, $author = null) { if ($author) { unset($data['status']); } else { $data['customer_id'] = $this->customerSession->getId(); $data['type'] = '1'; $data['status'] = $this->_helperBlog->getConfigGeneral('auto_approve'); } if ($this->getRequest()->getFiles()['image']['size'] > 0) { try { $this->imageHelper->uploadImage($data, 'image', Image::TEMPLATE_MEDIA_TYPE_AUTH); } catch (Exception $exception) { $data['image'] = isset($data['image']['value']) ? $data['image']['value'] : ''; } } if (isset($data['image']['delete'])) { $data['image'] = ''; } return $data; } }