Preview.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Controller\Adminhtml\Post;
  9. /**
  10. * Blog post preview controller
  11. */
  12. class Preview extends \Magefan\Blog\Controller\Adminhtml\Post
  13. {
  14. public function execute()
  15. {
  16. try {
  17. $post = $this->_getModel();
  18. if (!$post->getId()) {
  19. throw new \Exception("Item is not longer exist.", 1);
  20. }
  21. $previewUrl = $this->_objectManager->get('\Magefan\Blog\Model\PreviewUrl');
  22. $redirectUrl = $previewUrl->getUrl(
  23. $post,
  24. $previewUrl::CONTROLLER_POST
  25. );
  26. $this->getResponse()->setRedirect($redirectUrl);
  27. } catch (\Exception $e) {
  28. $this->messageManager->addException(
  29. $e,
  30. __('Something went wrong %1', $e->getMessage())
  31. );
  32. $this->_redirect('*/*/edit', [$this->_idKey => $post->getId()]);
  33. }
  34. }
  35. }