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
7 
10 
18 {
22  protected $_template = 'Magento_Newsletter::queue/edit.phtml';
23 
29  protected $_coreRegistry = null;
30 
36  public function __construct(
37  \Magento\Backend\Block\Template\Context $context,
38  \Magento\Framework\Registry $registry,
39  array $data = []
40  ) {
41  $this->_coreRegistry = $registry;
42  parent::__construct($context, $data);
43  }
44 
48  protected function _construct()
49  {
50  parent::_construct();
51  $templateId = $this->getRequest()->getParam('template_id');
52  if ($templateId) {
53  $this->setTemplateId($templateId);
54  }
55  }
56 
62  public function getQueue()
63  {
64  return $this->_coreRegistry->registry('current_queue');
65  }
66 
72  protected function _beforeToHtml()
73  {
74  $this->setChild(
75  'form',
76  $this->getLayout()->createBlock(\Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form::class, 'form')
77  );
78  return parent::_beforeToHtml();
79  }
80 
86  public function getSaveUrl()
87  {
88  if ($this->getTemplateId()) {
89  $params = ['template_id' => $this->getTemplateId()];
90  } else {
91  $params = ['id' => $this->getRequest()->getParam('id')];
92  }
93  return $this->getUrl('*/*/save', $params);
94  }
95 
101  protected function _prepareLayout()
102  {
103  $this->getToolbar()->addChild(
104  'back_button',
105  \Magento\Backend\Block\Widget\Button::class,
106  [
107  'label' => __('Back'),
108  'onclick' => "window.location.href = '" . $this->getUrl(
109  $this->getTemplateId() ? '*/template' : '*/*'
110  ) . "'",
111  'class' => 'action-back'
112  ]
113  );
114 
115  $this->getToolbar()->addChild(
116  'reset_button',
117  \Magento\Backend\Block\Widget\Button::class,
118  ['label' => __('Reset'), 'class' => 'reset', 'onclick' => 'window.location = window.location']
119  );
120 
121  $this->getToolbar()->addChild(
122  'preview_button',
123  \Magento\Backend\Block\Widget\Button::class,
124  ['label' => __('Preview Template'), 'onclick' => 'queueControl.preview();', 'class' => 'preview']
125  );
126 
127  $this->getToolbar()->addChild(
128  'save_button',
129  \Magento\Backend\Block\Widget\Button::class,
130  [
131  'label' => __('Save Newsletter'),
132  'class' => 'save primary',
133  'data_attribute' => [
134  'mage-init' => ['button' => ['event' => 'save', 'target' => '#queue_edit_form']],
135  ]
136  ]
137  );
138 
139  $this->getToolbar()->addChild(
140  'save_and_resume',
141  \Magento\Backend\Block\Widget\Button::class,
142  [
143  'label' => __('Save and Resume'),
144  'class' => 'save',
145  'data_attribute' => [
146  'mage-init' => [
147  'button' => [
148  'event' => 'save',
149  'target' => '#queue_edit_form',
150  'eventData' => ['action' => ['args' => ['_resume' => 1]]],
151  ],
152  ],
153  ]
154  ]
155  );
156 
157  return parent::_prepareLayout();
158  }
159 
165  public function getPreviewUrl()
166  {
167  if ($this->getTemplateId()) {
168  $params = ['template_id' => $this->getTemplateId()];
169  } else {
170  $params = ['id' => $this->getRequest()->getParam('id')];
171  }
172  return $this->getUrl('*/*/preview', $params);
173  }
174 
180  public function getPreviewButtonHtml()
181  {
182  return $this->getChildHtml('preview_button');
183  }
184 
190  public function getSaveButtonHtml()
191  {
192  return $this->getChildHtml('save_button');
193  }
194 
200  public function getResetButtonHtml()
201  {
202  return $this->getChildHtml('reset_button');
203  }
204 
210  public function getBackButtonHtml()
211  {
212  return $this->getChildHtml('back_button');
213  }
214 
220  public function getResumeButtonHtml()
221  {
222  return $this->getChildHtml('save_and_resume');
223  }
224 
231  public function getIsPreview()
232  {
233  return !in_array(
234  $this->getQueue()->getQueueStatus(),
235  [ModelQueue::STATUS_NEVER, ModelQueue::STATUS_PAUSE]
236  );
237  }
238 
244  protected function isSingleStoreMode()
245  {
246  return $this->_storeManager->isSingleStoreMode();
247  }
248 
255  protected function getStoreId()
256  {
257  return $this->_storeManager->getStore(true)->getId();
258  }
259 
266  public function getIsTextType()
267  {
268  return $this->getQueue()->isPlain();
269  }
270 
277  public function getCanResume()
278  {
279  return in_array($this->getQueue()->getQueueStatus(), [ModelQueue::STATUS_PAUSE]);
280  }
281 
288  public function getHeaderText()
289  {
290  return $this->getIsPreview() ? __('View Newsletter') : __('Edit Newsletter');
291  }
292 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, array $data=[])
Definition: Edit.php:36
$templateId
Definition: queue.php:15
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18