/** * run the action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPost('tag'); $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $tag = $this->initTag(); $tag->setData($data); $posts = $this->getRequest()->getPost('posts', -1); if ($posts != -1) { $tag->setPostsData($this->jsHelper->decodeGridSerializedInput($posts)); } $this->_eventManager->dispatch('mageplaza_blog_tag_prepare_save', ['tag' => $tag, 'request' => $this->getRequest()]); try { $tag->save(); $this->messageManager->addSuccess(__('The Tag has been saved.')); $this->backendSession->setMageplazaBlogTagData(false); if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('mageplaza_blog/*/edit', ['tag_id' => $tag->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 Tag.')); } $this->_getSession()->setMageplazaBlogTagData($data); $resultRedirect->setPath('mageplaza_blog/*/edit', ['tag_id' => $tag->getId(), '_current' => true]); return $resultRedirect; } $resultRedirect->setPath('mageplaza_blog/*/'); return $resultRedirect; }