Ejemplo n.º 1
0
 /**
  * run the action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('topic');
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $topic = $this->initTopic();
         $topic->setData($data);
         $posts = $this->getRequest()->getPost('posts', -1);
         if ($posts != -1) {
             $topic->setPostsData($this->jsHelper->decodeGridSerializedInput($posts));
         }
         $this->_eventManager->dispatch('mageplaza_blog_topic_prepare_save', ['topic' => $topic, 'request' => $this->getRequest()]);
         try {
             $topic->save();
             $this->messageManager->addSuccess(__('The Topic has been saved.'));
             $this->backendSession->setMageplazaBlogTopicData(false);
             if ($this->getRequest()->getParam('back')) {
                 $resultRedirect->setPath('mageplaza_blog/*/edit', ['topic_id' => $topic->getId(), '_current' => true]);
                 return $resultRedirect;
             }
             $resultRedirect->setPath('mageplaza_blog/*/');
             return $resultRedirect;
         } catch (\Magento\Framework\Exception\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 Topic.'));
         }
         $this->_getSession()->setMageplazaBlogTopicData($data);
         $resultRedirect->setPath('mageplaza_blog/*/edit', ['topic_id' => $topic->getId(), '_current' => true]);
         return $resultRedirect;
     }
     $resultRedirect->setPath('mageplaza_blog/*/');
     return $resultRedirect;
 }