PreviewButton.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Block\Adminhtml\Edit;
  9. use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
  10. /**
  11. * Class PreviewButton
  12. */
  13. class PreviewButton extends GenericButton implements ButtonProviderInterface
  14. {
  15. /**
  16. * @return array
  17. */
  18. public function getButtonData()
  19. {
  20. $data = [];
  21. if ($this->getPostId()) {
  22. $data = [
  23. 'label' => __('Preview'),
  24. 'class' => 'preview',
  25. 'on_click' => 'window.open(\'' . $this->getPreviewUrl() . '\');',
  26. 'sort_order' => 35,
  27. ];
  28. }
  29. return $data;
  30. }
  31. /**
  32. * @return string
  33. */
  34. public function getPreviewUrl()
  35. {
  36. return $this->getUrl('*/*/preview', ['id' => $this->getPostId()]);
  37. }
  38. }