9
9
use Magento \Contact \Model \ConfigInterface ;
10
10
use Magento \Contact \Model \MailInterface ;
11
11
use Magento \Framework \App \Action \Context ;
12
- use Magento \Framework \App \ObjectManager ;
13
12
use Magento \Framework \App \Request \DataPersistorInterface ;
14
13
use Magento \Framework \Controller \Result \Redirect ;
15
14
use Magento \Framework \Exception \LocalizedException ;
16
15
use Magento \Framework \HTTP \PhpEnvironment \Request ;
17
16
use Psr \Log \LoggerInterface ;
17
+ use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Framework \DataObject ;
18
19
19
20
class Post extends \Magento \Contact \Controller \Index
20
21
{
@@ -56,7 +57,7 @@ public function __construct(
56
57
$ this ->context = $ context ;
57
58
$ this ->mail = $ mail ;
58
59
$ this ->dataPersistor = $ dataPersistor ;
59
- $ this ->logger = $ logger ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (LoggerInterface::class);
60
+ $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
60
61
}
61
62
62
63
/**
@@ -71,45 +72,33 @@ public function execute()
71
72
}
72
73
try {
73
74
$ this ->sendEmail ($ this ->validatedParams ());
74
- $ this ->messageManager ->addSuccess (
75
+ $ this ->messageManager ->addSuccessMessage (
75
76
__ ('Thanks for contacting us with your comments and questions. We \'ll respond to you very soon. ' )
76
77
);
77
- $ this ->getDataPersistor () ->clear ('contact_us ' );
78
+ $ this ->dataPersistor ->clear ('contact_us ' );
78
79
} catch (LocalizedException $ e ) {
79
80
$ this ->messageManager ->addErrorMessage ($ e ->getMessage ());
80
- $ this ->getDataPersistor () ->set ('contact_us ' , $ this ->getRequest ()->getParams ());
81
+ $ this ->dataPersistor ->set ('contact_us ' , $ this ->getRequest ()->getParams ());
81
82
} catch (\Exception $ e ) {
82
83
$ this ->logger ->critical ($ e );
83
84
$ this ->messageManager ->addErrorMessage (
84
85
__ ('An error occurred while processing your form. Please try again later. ' )
85
86
);
86
- $ this ->getDataPersistor () ->set ('contact_us ' , $ this ->getRequest ()->getParams ());
87
+ $ this ->dataPersistor ->set ('contact_us ' , $ this ->getRequest ()->getParams ());
87
88
}
88
89
return $ this ->resultRedirectFactory ->create ()->setPath ('contact/index ' );
89
90
}
90
91
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
-
106
92
/**
107
93
* @param array $post Post data from contact form
108
94
* @return void
109
95
*/
110
96
private function sendEmail ($ post )
111
97
{
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
+ );
113
102
}
114
103
115
104
/**
0 commit comments