11
11
use Magento \Framework \Controller \ResultFactory ;
12
12
use Magento \Framework \Exception \State \UserLockedException ;
13
13
use Magento \Security \Model \SecurityCookie ;
14
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
14
15
15
16
/**
16
17
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
18
*/
18
- class Save extends \Magento \Backend \Controller \Adminhtml \System \Account
19
+ class Save extends \Magento \Backend \Controller \Adminhtml \System \Account implements HttpPostActionInterface
19
20
{
20
21
/**
21
22
* @var SecurityCookie
@@ -25,8 +26,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
25
26
/**
26
27
* Get security cookie
27
28
*
29
+ * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of
30
+ * directly accessing the SecurityCookie instance.
31
+ * Use dependency injection to get an instance of SecurityCookie.
32
+ * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct()
28
33
* @return SecurityCookie
29
- * @deprecated 100.1.0
30
34
*/
31
35
private function getSecurityCookie ()
32
36
{
@@ -81,7 +85,39 @@ public function execute()
81
85
} else {
82
86
$ user ->save ();
83
87
$ user ->sendNotificationEmailsIfRequired ();
84
- $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
88
+
89
+ // Check which fields were modified after saving
90
+ $ modifiedFields = [];
91
+ $ propertiesToCheck = ['password ' , 'username ' , 'firstname ' , 'lastname ' , 'email ' ];
92
+
93
+ foreach ($ propertiesToCheck as $ property ) {
94
+ if ($ user ->getOrigData ($ property ) !== $ user ->{'get ' . ucfirst ($ property )}()) {
95
+ $ modifiedFields [] = $ property ;
96
+ }
97
+ }
98
+
99
+ if (!empty ($ modifiedFields )) {
100
+ $ countModifiedFields = count ($ modifiedFields );
101
+ $ successMessage = '' ;
102
+ // validate how many fields were modified to display them correctly
103
+ if ($ countModifiedFields > 1 ) {
104
+ $ lastModifiedField = array_pop ($ modifiedFields );
105
+ $ modifiedFieldsText = implode (', ' , $ modifiedFields );
106
+ $ successMessage = __ (
107
+ 'The %1 and %2 of this account have been modified successfully. ' ,
108
+ $ modifiedFieldsText ,
109
+ $ lastModifiedField
110
+ );
111
+ } else {
112
+ $ successMessage = __ (
113
+ 'The %1 of this account has been modified successfully. ' ,
114
+ reset ($ modifiedFields )
115
+ );
116
+ }
117
+ $ this ->messageManager ->addSuccessMessage ($ successMessage );
118
+ } else {
119
+ $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
120
+ }
85
121
}
86
122
} catch (UserLockedException $ e ) {
87
123
$ this ->_auth ->logout ();
0 commit comments