Skip to content

Commit 4123e23

Browse files
author
Yuri Kovsher
committed
MAGETWO-36101: Refactor controllers in the Wishlist module
1 parent 0c817ab commit 4123e23

File tree

1 file changed

+28
-19
lines changed
  • app/code/Magento/Wishlist/Controller/Index

1 file changed

+28
-19
lines changed

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
use Magento\Framework\App\Action;
1010
use Magento\Framework\Exception\NotFoundException;
11-
use Magento\Framework\App\ResponseInterface;
1211
use Magento\Wishlist\Controller\IndexInterface;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\View\Result\Layout as ResultLayout;
1314

1415
/**
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,16 +85,19 @@ public function __construct(
8485
/**
8586
* Share wishlist
8687
*
87-
* @return ResponseInterface|void
88+
* @return \Magento\Framework\Controller\Result\Redirect
8889
* @throws NotFoundException
8990
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
9091
* @SuppressWarnings(PHPMD.NPathComplexity)
9192
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
9293
*/
9394
public function execute()
9495
{
96+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
97+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
9598
if (!$this->_formKeyValidator->validate($this->getRequest())) {
96-
return $this->_redirect('*/*/');
99+
$resultRedirect->setPath('*/*/');
100+
return $resultRedirect;
97101
}
98102

99103
$wishlist = $this->wishlistProvider->getWishlist();
@@ -136,11 +140,12 @@ public function execute()
136140
)->setSharingForm(
137141
$this->getRequest()->getPostValue()
138142
);
139-
$this->_redirect('*/*/share');
140-
return;
143+
$resultRedirect->setPath('*/*/share');
144+
return $resultRedirect;
141145
}
142-
143-
$this->addLayoutHandles();
146+
/** @var \Magento\Framework\View\Result\Layout $resultLayout */
147+
$resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
148+
$this->addLayoutHandles($resultLayout);
144149
$this->inlineTranslation->suspend();
145150

146151
$sent = 0;
@@ -149,7 +154,7 @@ public function execute()
149154
$customer = $this->_customerSession->getCustomerDataObject();
150155
$customerName = $this->_customerHelperView->getCustomerName($customer);
151156

152-
$message .= $this->getRssLink($wishlist->getId());
157+
$message .= $this->getRssLink($wishlist->getId(), $resultLayout);
153158
$emails = array_unique($emails);
154159
$sharingCode = $wishlist->getSharingCode();
155160

@@ -172,7 +177,7 @@ public function execute()
172177
'customer' => $customer,
173178
'customerName' => $customerName,
174179
'salable' => $wishlist->isSalable() ? 'yes' : '',
175-
'items' => $this->getWishlistItems(),
180+
'items' => $this->getWishlistItems($resultLayout),
176181
'addAllLink' => $this->_url->getUrl('*/shared/allcart', ['code' => $sharingCode]),
177182
'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', ['code' => $sharingCode]),
178183
'message' => $message,
@@ -203,7 +208,8 @@ public function execute()
203208

204209
$this->_eventManager->dispatch('wishlist_share', ['wishlist' => $wishlist]);
205210
$this->messageManager->addSuccess(__('Your wish list has been shared.'));
206-
$this->_redirect('*/*', ['wishlist_id' => $wishlist->getId()]);
211+
$resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]);
212+
return $resultRedirect;
207213
} catch (\Exception $e) {
208214
$this->inlineTranslation->resume();
209215
$this->messageManager->addError($e->getMessage());
@@ -212,7 +218,8 @@ public function execute()
212218
)->setSharingForm(
213219
$this->getRequest()->getPostValue()
214220
);
215-
$this->_redirect('*/*/share');
221+
$resultRedirect->setPath('*/*/share');
222+
return $resultRedirect;
216223
}
217224
}
218225

@@ -222,27 +229,28 @@ public function execute()
222229
* Add 'wishlist_email_rss' layout handle.
223230
* Add 'wishlist_email_items' layout handle.
224231
*
232+
* @param \Magento\Framework\View\Result\Layout $resultLayout
225233
* @return void
226234
*/
227-
protected function addLayoutHandles()
235+
protected function addLayoutHandles(ResultLayout $resultLayout)
228236
{
229237
if ($this->getRequest()->getParam('rss_url')) {
230-
$this->_view->getLayout()->getUpdate()->addHandle('wishlist_email_rss');
238+
$resultLayout->addHandle('wishlist_email_rss');
231239
}
232-
$this->_view->getLayout()->getUpdate()->addHandle('wishlist_email_items');
233-
$this->_view->loadLayoutUpdates();
240+
$resultLayout->addHandle('wishlist_email_items');
234241
}
235242

236243
/**
237244
* Retrieve RSS link content (html)
238245
*
239246
* @param int $wishlistId
247+
* @param \Magento\Framework\View\Result\Layout $resultLayout
240248
* @return mixed
241249
*/
242-
protected function getRssLink($wishlistId)
250+
protected function getRssLink($wishlistId, ResultLayout $resultLayout)
243251
{
244252
if ($this->getRequest()->getParam('rss_url')) {
245-
return $this->_view->getLayout()
253+
return $resultLayout->getLayout()
246254
->getBlock('wishlist.email.rss')
247255
->setWishlistId($wishlistId)
248256
->toHtml();
@@ -252,11 +260,12 @@ protected function getRssLink($wishlistId)
252260
/**
253261
* Retrieve wishlist items content (html)
254262
*
263+
* @param \Magento\Framework\View\Result\Layout $resultLayout
255264
* @return string
256265
*/
257-
protected function getWishlistItems()
266+
protected function getWishlistItems(ResultLayout $resultLayout)
258267
{
259-
return $this->_view->getLayout()
268+
return $resultLayout->getLayout()
260269
->getBlock('wishlist.email.items')
261270
->toHtml();
262271
}

0 commit comments

Comments
 (0)