Skip to content

Commit 2497062

Browse files
Merge forwardport of #12061 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12061.patch (created by @atishgoswami) based on commit(s): 1. b30eda5 2. 9e63c27 3. bd8758d 4. 75379cf
2 parents 8e77e2f + b415941 commit 2497062

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

app/code/Magento/Contact/Controller/Index/Post.php

+11-22
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
use Magento\Contact\Model\ConfigInterface;
1010
use Magento\Contact\Model\MailInterface;
1111
use Magento\Framework\App\Action\Context;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Framework\App\Request\DataPersistorInterface;
1413
use Magento\Framework\Controller\Result\Redirect;
1514
use Magento\Framework\Exception\LocalizedException;
1615
use Magento\Framework\HTTP\PhpEnvironment\Request;
1716
use Psr\Log\LoggerInterface;
17+
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\DataObject;
1819

1920
class Post extends \Magento\Contact\Controller\Index
2021
{
@@ -56,7 +57,7 @@ public function __construct(
5657
$this->context = $context;
5758
$this->mail = $mail;
5859
$this->dataPersistor = $dataPersistor;
59-
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LoggerInterface::class);
60+
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
6061
}
6162

6263
/**
@@ -71,45 +72,33 @@ public function execute()
7172
}
7273
try {
7374
$this->sendEmail($this->validatedParams());
74-
$this->messageManager->addSuccess(
75+
$this->messageManager->addSuccessMessage(
7576
__('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
7677
);
77-
$this->getDataPersistor()->clear('contact_us');
78+
$this->dataPersistor->clear('contact_us');
7879
} catch (LocalizedException $e) {
7980
$this->messageManager->addErrorMessage($e->getMessage());
80-
$this->getDataPersistor()->set('contact_us', $this->getRequest()->getParams());
81+
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
8182
} catch (\Exception $e) {
8283
$this->logger->critical($e);
8384
$this->messageManager->addErrorMessage(
8485
__('An error occurred while processing your form. Please try again later.')
8586
);
86-
$this->getDataPersistor()->set('contact_us', $this->getRequest()->getParams());
87+
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
8788
}
8889
return $this->resultRedirectFactory->create()->setPath('contact/index');
8990
}
9091

91-
/**
92-
* Get Data Persistor
93-
*
94-
* @return DataPersistorInterface
95-
*/
96-
private function getDataPersistor()
97-
{
98-
if ($this->dataPersistor === null) {
99-
$this->dataPersistor = ObjectManager::getInstance()
100-
->get(DataPersistorInterface::class);
101-
}
102-
103-
return $this->dataPersistor;
104-
}
105-
10692
/**
10793
* @param array $post Post data from contact form
10894
* @return void
10995
*/
11096
private function sendEmail($post)
11197
{
112-
$this->mail->send($post['email'], ['data' => new \Magento\Framework\DataObject($post)]);
98+
$this->mail->send(
99+
$post['email'],
100+
['data' => new DataObject($post)]
101+
);
113102
}
114103

115104
/**

app/code/Magento/Contact/Model/Mail.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
namespace Magento\Contact\Model;
77

88
use Magento\Framework\Mail\Template\TransportBuilder;
9-
use Magento\Framework\App\ObjectManager;
109
use Magento\Framework\Translate\Inline\StateInterface;
1110
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\Area;
1213

1314
class Mail implements MailInterface
1415
{
@@ -49,8 +50,7 @@ public function __construct(
4950
$this->contactsConfig = $contactsConfig;
5051
$this->transportBuilder = $transportBuilder;
5152
$this->inlineTranslation = $inlineTranslation;
52-
$this->storeManager = $storeManager ?:
53-
ObjectManager::getInstance()->get(StoreManagerInterface::class);
53+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
5454
}
5555

5656
/**
@@ -71,7 +71,7 @@ public function send($replyTo, array $variables)
7171
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
7272
->setTemplateOptions(
7373
[
74-
'area' => 'frontend',
74+
'area' => Area::AREA_FRONTEND,
7575
'store' => $this->storeManager->getStore()->getId()
7676
]
7777
)

dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testPostAction()
2424
$this->assertRedirect($this->stringContains('contact/index'));
2525
$this->assertSessionMessages(
2626
$this->contains(
27-
"Thanks for contacting us with your comments and questions. We'll respond to you very soon."
27+
"Thanks for contacting us with your comments and questions. We'll respond to you very soon."
2828
),
2929
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
3030
);

0 commit comments

Comments
 (0)