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 
11 class Edit extends \Magento\Backend\Block\Widget\Form\Container
12 {
18  protected $_reviewActionPager = null;
19 
25  protected $_coreRegistry = null;
26 
32  protected $_reviewFactory;
33 
41  public function __construct(
42  \Magento\Backend\Block\Widget\Context $context,
43  \Magento\Review\Model\ReviewFactory $reviewFactory,
44  \Magento\Review\Helper\Action\Pager $reviewActionPager,
45  \Magento\Framework\Registry $registry,
46  array $data = []
47  ) {
48  $this->_coreRegistry = $registry;
49  $this->_reviewActionPager = $reviewActionPager;
50  $this->_reviewFactory = $reviewFactory;
51  parent::__construct($context, $data);
52  }
53 
60  protected function _construct()
61  {
62  parent::_construct();
63 
64  $this->_objectId = 'id';
65  $this->_blockGroup = 'Magento_Review';
66  $this->_controller = 'adminhtml';
67 
69  $actionPager = $this->_reviewActionPager;
70  $actionPager->setStorageId('reviews');
71 
72  $reviewId = $this->getRequest()->getParam('id');
73  $prevId = $actionPager->getPreviousItemId($reviewId);
74  $nextId = $actionPager->getNextItemId($reviewId);
75  if ($prevId !== false) {
76  $this->addButton(
77  'previous',
78  [
79  'label' => __('Previous'),
80  'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $prevId]) . '\')'
81  ],
82  3,
83  10
84  );
85 
86  $this->addButton(
87  'save_and_previous',
88  [
89  'label' => __('Save and Previous'),
90  'class' => 'save',
91  'data_attribute' => [
92  'mage-init' => [
93  'button' => [
94  'event' => 'save',
95  'target' => '#edit_form',
96  'eventData' => ['action' => ['args' => ['next_item' => $prevId]]],
97  ],
98  ],
99  ]
100  ],
101  3,
102  11
103  );
104  }
105  if ($nextId !== false) {
106  $this->addButton(
107  'save_and_next',
108  [
109  'label' => __('Save and Next'),
110  'class' => 'save',
111  'data_attribute' => [
112  'mage-init' => [
113  'button' => [
114  'event' => 'save',
115  'target' => '#edit_form',
116  'eventData' => ['action' => ['args' => ['next_item' => $nextId]]],
117  ],
118  ],
119  ]
120  ],
121  3,
122  100
123  );
124 
125  $this->addButton(
126  'next',
127  [
128  'label' => __('Next'),
129  'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $nextId]) . '\')'
130  ],
131  3,
132  105
133  );
134  }
135  $this->buttonList->update('save', 'label', __('Save Review'));
136  $this->buttonList->update('save', 'id', 'save_button');
137  $this->buttonList->update('delete', 'label', __('Delete Review'));
138 
139  if ($this->getRequest()->getParam('productId', false)) {
140  $this->buttonList->update(
141  'back',
142  'onclick',
143  'setLocation(\'' . $this->getUrl(
144  'catalog/product/edit',
145  ['id' => $this->getRequest()->getParam('productId', false)]
146  ) . '\')'
147  );
148  }
149 
150  if ($this->getRequest()->getParam('customerId', false)) {
151  $this->buttonList->update(
152  'back',
153  'onclick',
154  'setLocation(\'' . $this->getUrl(
155  'customer/index/edit',
156  ['id' => $this->getRequest()->getParam('customerId', false)]
157  ) . '\')'
158  );
159  }
160 
161  if ($this->getRequest()->getParam('ret', false) == 'pending') {
162  $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('catalog/*/pending') . '\')');
163  $this->buttonList->update(
164  'delete',
165  'onclick',
166  'deleteConfirm(' . '\'' . __(
167  'Are you sure you want to do this?'
168  ) . '\' ' . '\'' . $this->getUrl(
169  '*/*/delete',
170  [$this->_objectId => $this->getRequest()->getParam($this->_objectId), 'ret' => 'pending']
171  ) . '\'' . ')'
172  );
173  $this->_coreRegistry->register('ret', 'pending');
174  }
175 
176  if ($this->getRequest()->getParam($this->_objectId)) {
177  $reviewData = $this->_reviewFactory->create()->load($this->getRequest()->getParam($this->_objectId));
178  $this->_coreRegistry->register('review_data', $reviewData);
179  }
180 
181  $this->_formInitScripts[] = '
182  var review = {
183  updateRating: function() {
184  elements = [
185  $("select_stores"),
186  $("rating_detail").getElementsBySelector("input[type=\'radio\']")
187  ].flatten();
188  $(\'save_button\').disabled = true;
189  new Ajax.Updater(
190  "rating_detail",
191  "' .
192  $this->getUrl(
193  'review/*/ratingItems',
194  ['_current' => true]
195  ) .
196  '",
197  {
198  parameters:Form.serializeElements(elements),
199  evalScripts:true,
200  onComplete:function(){ $(\'save_button\').disabled = false; }
201  }
202  );
203  }
204  }
205  Event.observe(window, \'load\', function(){
206  Event.observe($("select_stores"), \'change\', review.updateRating);
207  });
208  ';
209  }
210 
216  public function getHeaderText()
217  {
218  $reviewData = $this->_coreRegistry->registry('review_data');
219  if ($reviewData && $reviewData->getId()) {
220  return __("Edit Review '%1'", $this->escapeHtml($reviewData->getTitle()));
221  } else {
222  return __('New Review');
223  }
224  }
225 }
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Review\Model\ReviewFactory $reviewFactory, \Magento\Review\Helper\Action\Pager $reviewActionPager, \Magento\Framework\Registry $registry, array $data=[])
Definition: Edit.php:41
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85