Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
13 
16 
21 class Edit extends Widget
22 {
28  protected $_coreRegistry = null;
29 
33  protected $_wysiwygConfig;
34 
41  public function __construct(
42  \Magento\Backend\Block\Template\Context $context,
43  \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
44  \Magento\Framework\Registry $registry,
45  array $data = []
46  ) {
47  $this->_coreRegistry = $registry;
48  $this->_wysiwygConfig = $wysiwygConfig;
49  parent::__construct($context, $data);
50  }
51 
57  public function getModel()
58  {
59  return $this->_coreRegistry->registry('_current_template');
60  }
61 
68  protected function _prepareLayout()
69  {
70  $this->getToolbar()->addChild(
71  'back_button',
72  \Magento\Backend\Block\Widget\Button::class,
73  [
74  'label' => __('Back'),
75  'onclick' => "window.location.href = '" . $this->getUrl('*/*') . "'",
76  'class' => 'action-back'
77  ]
78  );
79 
80  $this->getToolbar()->addChild(
81  'reset_button',
82  \Magento\Backend\Block\Widget\Button::class,
83  [
84  'label' => __('Reset'),
85  'onclick' => 'window.location.href = window.location.href',
86  'class' => 'reset'
87  ]
88  );
89 
90  if (!$this->isTextType()) {
91  $this->getToolbar()->addChild(
92  'to_plain_button',
93  \Magento\Backend\Block\Widget\Button::class,
94  [
95  'label' => __('Convert to Plain Text'),
96  'data_attribute' => [
97  'role' => 'template-strip',
98  ],
99  'id' => 'convert_button',
100  'class' => 'convert'
101  ]
102  );
103 
104  $this->getToolbar()->addChild(
105  'to_html_button',
106  \Magento\Backend\Block\Widget\Button::class,
107  [
108  'label' => __('Return HTML Version'),
109  'data_attribute' => [
110  'role' => 'template-unstrip',
111  ],
112  'id' => 'convert_button_back',
113  'style' => 'display:none',
114  'class' => 'return'
115  ]
116  );
117  }
118 
119  $this->getToolbar()->addChild(
120  'preview_button',
121  \Magento\Backend\Block\Widget\Button::class,
122  [
123  'label' => __('Preview Template'),
124  'data_attribute' => [
125  'role' => 'template-preview',
126  ],
127  'class' => 'preview'
128  ]
129  );
130 
131  if ($this->getEditMode()) {
132  $this->getToolbar()->addChild(
133  'delete_button',
134  \Magento\Backend\Block\Widget\Button::class,
135  [
136  'label' => __('Delete Template'),
137  'data_attribute' => [
138  'role' => 'template-delete',
139  ],
140  'class' => 'delete'
141  ]
142  );
143 
144  $this->getToolbar()->addChild(
145  'save_as_button',
146  \Magento\Backend\Block\Widget\Button::class,
147  [
148  'label' => __('Save As'),
149  'data_attribute' => [
150  'role' => 'template-save-as',
151  ],
152  'class' => 'save-as'
153  ]
154  );
155  }
156 
157  $this->getToolbar()->addChild(
158  'save_button',
159  \Magento\Backend\Block\Widget\Button::class,
160  [
161  'label' => __('Save Template'),
162  'data_attribute' => [
163  'role' => 'template-save',
164  ],
165  'class' => 'save primary'
166  ]
167  );
168 
169  return parent::_prepareLayout();
170  }
171 
178  public function getEditMode()
179  {
180  if ($this->getModel()->getId()) {
181  return true;
182  }
183  return false;
184  }
185 
191  public function getHeaderText()
192  {
193  if ($this->getEditMode()) {
194  return __('Edit Newsletter Template');
195  }
196 
197  return __('New Newsletter Template');
198  }
199 
205  public function getForm()
206  {
207  return $this->getLayout()->createBlock(
208  \Magento\Newsletter\Block\Adminhtml\Template\Edit\Form::class
209  )->toHtml();
210  }
211 
217  public function getJsTemplateName()
218  {
219  return addcslashes($this->getModel()->getTemplateCode(), "\"\r\n\\");
220  }
221 
227  public function getSaveUrl()
228  {
229  return $this->getUrl('*/*/save');
230  }
231 
237  public function getPreviewUrl()
238  {
239  return $this->getUrl('*/*/preview', ['id' => $this->getRequest()->getParam('id')]);
240  }
241 
247  public function isTextType()
248  {
249  return $this->getModel()->isPlain();
250  }
251 
257  public function getTemplateType()
258  {
259  if ($this->getModel()->getTemplateType()) {
260  return $this->getModel()->getTemplateType();
261  }
262  return TemplateTypesInterface::TYPE_HTML;
263  }
264 
270  public function getDeleteUrl()
271  {
272  return $this->getUrl('*/*/delete', ['id' => $this->getRequest()->getParam('id')]);
273  }
274 
280  public function getSaveAsFlag()
281  {
282  return $this->getRequest()->getParam('_save_as_flag') ? '1' : '';
283  }
284 
290  protected function isSingleStoreMode()
291  {
292  return $this->_storeManager->isSingleStoreMode();
293  }
294 
300  protected function getStoreId()
301  {
302  return $this->_storeManager->getStore(true)->getId();
303  }
304 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, \Magento\Framework\Registry $registry, array $data=[])
Definition: Edit.php:41
__()
Definition: __.php:13