/** * run the action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPost('author'); $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $data = $this->filterData($data); $author = $this->initAuthor(); $author->setData($data); $avatar = $this->uploadModel->uploadFileAndGetName('avatar', $this->imageModel->getBaseDir(), $data); $author->setAvatar($avatar); $resume = $this->uploadModel->uploadFileAndGetName('resume', $this->fileModel->getBaseDir(), $data); $author->setResume($resume); $products = $this->getRequest()->getPost('products', -1); if ($products != -1) { $author->setProductsData($this->jsHelper->decodeGridSerializedInput($products)); } $this->_eventManager->dispatch('sample_news_author_prepare_save', ['author' => $author, 'request' => $this->getRequest()]); try { $author->save(); $this->messageManager->addSuccess(__('The author has been saved.')); $this->_getSession()->setSampleNewsAuthorData(false); if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('sample_news/*/edit', ['author_id' => $author->getId(), '_current' => true]); return $resultRedirect; } $resultRedirect->setPath('sample_news/*/'); return $resultRedirect; } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\RuntimeException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the author.')); } $this->_getSession()->setSampleNewsAuthorData($data); $resultRedirect->setPath('sample_news/*/edit', ['author_id' => $author->getId(), '_current' => true]); return $resultRedirect; } $resultRedirect->setPath('sample_news/*/'); return $resultRedirect; }