resultRedirectFactory->create(); $postId = null; if ($id = $this->getRequest()->getParam('id')) { try { $history = $this->postHistoryFactory->create() ->load($id); $postId = $history->getPostId(); $history->delete(); $this->messageManager->addSuccessMessage(__('The Post History has been deleted.')); } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } } else { $this->messageManager->addErrorMessage(__('Post History to delete was not found.')); } if ($postId) { $resultRedirect->setPath('mageplaza_blog/post/edit', ['id' => $postId]); } else { $resultRedirect->setPath('mageplaza_blog/post/index'); } return $resultRedirect; } }