Edit.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © 2016 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\Post;
  9. /**
  10. * Admin blog post
  11. */
  12. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  13. {
  14. /**
  15. * Core registry
  16. *
  17. * @var \Magento\Framework\Registry
  18. */
  19. protected $_coreRegistry = null;
  20. /**
  21. * @param \Magento\Backend\Block\Widget\Context $context
  22. * @param \Magento\Framework\Registry $registry
  23. * @param array $data
  24. */
  25. public function __construct(
  26. \Magento\Backend\Block\Widget\Context $context,
  27. \Magento\Framework\Registry $registry,
  28. array $data = []
  29. ) {
  30. $this->_coreRegistry = $registry;
  31. parent::__construct($context, $data);
  32. }
  33. /**
  34. * Initialize cms page edit block
  35. *
  36. * @return void
  37. */
  38. protected function _construct()
  39. {
  40. $this->_objectId = 'id';
  41. $this->_blockGroup = 'Magefan_Blog';
  42. $this->_controller = 'adminhtml_post';
  43. parent::_construct();
  44. if ($this->_isAllowedAction('Magefan_Blog::post')) {
  45. $this->buttonList->add(
  46. 'saveandcontinue',
  47. [
  48. 'label' => __('Save and Continue Edit'),
  49. 'class' => 'save',
  50. 'data_attribute' => [
  51. 'mage-init' => [
  52. 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
  53. ],
  54. ]
  55. ],
  56. -100
  57. );
  58. } else {
  59. $this->buttonList->remove('save');
  60. }
  61. if (!$this->_isAllowedAction('Magefan_Blog::post')) {
  62. $this->buttonList->remove('delete');
  63. }
  64. }
  65. /**
  66. * Check permission for passed action
  67. *
  68. * @param string $resourceId
  69. * @return bool
  70. */
  71. protected function _isAllowedAction($resourceId)
  72. {
  73. return $this->_authorization->isAllowed($resourceId);
  74. }
  75. /**
  76. * Getter of url for "Save and Continue" button
  77. * tab_id will be replaced by desired by JS later
  78. *
  79. * @return string
  80. */
  81. protected function _getSaveAndContinueUrl()
  82. {
  83. return $this->getUrl('*/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']);
  84. }
  85. /**
  86. * Prepare layout
  87. *
  88. * @return \Magento\Framework\View\Element\AbstractBlock
  89. */
  90. protected function _prepareLayout()
  91. {
  92. $this->_formScripts[] = "
  93. function toggleEditor() {
  94. if (tinyMCE.getInstanceById('post_content') == null) {
  95. tinyMCE.execCommand('mceAddControl', false, 'post_content');
  96. } else {
  97. tinyMCE.execCommand('mceRemoveControl', false, 'post_content');
  98. }
  99. };
  100. ";
  101. return parent::_prepareLayout();
  102. }
  103. }