Skip to content

Commit 8d0b856

Browse files
authored
ENGCOM-4409: Fix type hints and replace deprecated method usage #21536
2 parents 393d5f9 + dadab1a commit 8d0b856

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

app/code/Magento/Newsletter/Controller/Subscriber/Confirm.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
78
namespace Magento\Newsletter\Controller\Subscriber;
89

9-
class Confirm extends \Magento\Newsletter\Controller\Subscriber
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
12+
/**
13+
* Confirm subscription controller.
14+
*/
15+
class Confirm extends \Magento\Newsletter\Controller\Subscriber implements HttpGetActionInterface
1016
{
1117
/**
12-
* Subscription confirm action
13-
* @return void
18+
* Subscription confirm action.
19+
*
20+
* @return \Magento\Framework\Controller\Result\Redirect
1421
*/
1522
public function execute()
1623
{
@@ -23,17 +30,17 @@ public function execute()
2330

2431
if ($subscriber->getId() && $subscriber->getCode()) {
2532
if ($subscriber->confirm($code)) {
26-
$this->messageManager->addSuccess(__('Your subscription has been confirmed.'));
33+
$this->messageManager->addSuccessMessage(__('Your subscription has been confirmed.'));
2734
} else {
28-
$this->messageManager->addError(__('This is an invalid subscription confirmation code.'));
35+
$this->messageManager->addErrorMessage(__('This is an invalid subscription confirmation code.'));
2936
}
3037
} else {
31-
$this->messageManager->addError(__('This is an invalid subscription ID.'));
38+
$this->messageManager->addErrorMessage(__('This is an invalid subscription ID.'));
3239
}
3340
}
34-
35-
$resultRedirect = $this->resultRedirectFactory->create();
36-
$resultRedirect->setUrl($this->_storeManager->getStore()->getBaseUrl());
37-
return $resultRedirect;
41+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
42+
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
43+
$redirectUrl = $this->_storeManager->getStore()->getBaseUrl();
44+
return $redirect->setUrl($redirectUrl);
3845
}
3946
}

app/code/Magento/Newsletter/Controller/Subscriber/NewAction.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
78
namespace Magento\Newsletter\Controller\Subscriber;
89

910
use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement;
@@ -131,7 +132,7 @@ protected function validateEmailFormat($email)
131132
/**
132133
* New subscription action
133134
*
134-
* @return void
135+
* @return \Magento\Framework\Controller\Result\Redirect
135136
*/
136137
public function execute()
137138
{
@@ -160,7 +161,10 @@ public function execute()
160161
$this->messageManager->addExceptionMessage($e, __('Something went wrong with the subscription.'));
161162
}
162163
}
163-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
164+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
165+
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
166+
$redirectUrl = $this->_redirect->getRedirectUrl();
167+
return $redirect->setUrl($redirectUrl);
164168
}
165169

166170
/**

app/code/Magento/Newsletter/Controller/Subscriber/Unsubscribe.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Newsletter\Controller\Subscriber;
78

89
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
@@ -15,7 +16,7 @@ class Unsubscribe extends \Magento\Newsletter\Controller\Subscriber implements H
1516
/**
1617
* Unsubscribe newsletter.
1718
*
18-
* @return \Magento\Backend\Model\View\Result\Redirect
19+
* @return \Magento\Framework\Controller\Result\Redirect
1920
*/
2021
public function execute()
2122
{
@@ -25,14 +26,14 @@ public function execute()
2526
if ($id && $code) {
2627
try {
2728
$this->_subscriberFactory->create()->load($id)->setCheckCode($code)->unsubscribe();
28-
$this->messageManager->addSuccess(__('You unsubscribed.'));
29+
$this->messageManager->addSuccessMessage(__('You unsubscribed.'));
2930
} catch (\Magento\Framework\Exception\LocalizedException $e) {
30-
$this->messageManager->addException($e, $e->getMessage());
31+
$this->messageManager->addErrorMessage($e, $e->getMessage());
3132
} catch (\Exception $e) {
32-
$this->messageManager->addException($e, __('Something went wrong while unsubscribing you.'));
33+
$this->messageManager->addErrorMessage($e, __('Something went wrong while unsubscribing you.'));
3334
}
3435
}
35-
/** @var \Magento\Backend\Model\View\Result\Redirect $redirect */
36+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
3637
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
3738
$redirectUrl = $this->_redirect->getRedirectUrl();
3839
return $redirect->setUrl($redirectUrl);

0 commit comments

Comments
 (0)