1111use Magento \Framework \Controller \ResultFactory ;
1212use Magento \Framework \Exception \State \UserLockedException ;
1313use Magento \Security \Model \SecurityCookie ;
14+ use Magento \Framework \App \Action \HttpPostActionInterface ;
1415
1516/**
1617 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1718 */
18- class Save extends \Magento \Backend \Controller \Adminhtml \System \Account
19+ class Save extends \Magento \Backend \Controller \Adminhtml \System \Account implements HttpPostActionInterface
1920{
2021 /**
2122 * @var SecurityCookie
@@ -25,8 +26,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
2526 /**
2627 * Get security cookie
2728 *
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()
2833 * @return SecurityCookie
29- * @deprecated 100.1.0
3034 */
3135 private function getSecurityCookie ()
3236 {
@@ -81,7 +85,39 @@ public function execute()
8185 } else {
8286 $ user ->save ();
8387 $ 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+ }
85121 }
86122 } catch (UserLockedException $ e ) {
87123 $ this ->_auth ->logout ();
0 commit comments