11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved .
55 */
66namespace Magento \Backend \Controller \Adminhtml \System \Account ;
77
1111use Magento \Framework \Controller \ResultFactory ;
1212use Magento \Framework \Exception \State \UserLockedException ;
1313use Magento \Security \Model \SecurityCookie ;
14+ use Magento \User \Model \User ;
1415
1516/**
1617 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+ * @SuppressWarnings(PHPMD.AllPurposeAction)
1719 */
1820class Save extends \Magento \Backend \Controller \Adminhtml \System \Account
1921{
@@ -25,8 +27,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
2527 /**
2628 * Get security cookie
2729 *
30+ * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of
31+ * directly accessing the SecurityCookie instance.
32+ * Use dependency injection to get an instance of SecurityCookie.
33+ * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct()
2834 * @return SecurityCookie
29- * @deprecated 100.1.0
3035 */
3136 private function getSecurityCookie ()
3237 {
@@ -81,7 +86,29 @@ public function execute()
8186 } else {
8287 $ user ->save ();
8388 $ user ->sendNotificationEmailsIfRequired ();
84- $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
89+
90+ $ modifiedFields = $ this ->getModifiedFields ($ user );
91+ if (!empty ($ modifiedFields )) {
92+ $ countModifiedFields = count ($ modifiedFields );
93+ // validate how many fields were modified to display them correctly
94+ if ($ countModifiedFields > 1 ) {
95+ $ lastModifiedField = array_pop ($ modifiedFields );
96+ $ modifiedFieldsText = implode (', ' , $ modifiedFields );
97+ $ successMessage = __ (
98+ 'The %1 and %2 of this account have been modified successfully. ' ,
99+ $ modifiedFieldsText ,
100+ $ lastModifiedField
101+ );
102+ } else {
103+ $ successMessage = __ (
104+ 'The %1 of this account has been modified successfully. ' ,
105+ reset ($ modifiedFields )
106+ );
107+ }
108+ $ this ->messageManager ->addSuccessMessage ($ successMessage );
109+ } else {
110+ $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
111+ }
85112 }
86113 } catch (UserLockedException $ e ) {
87114 $ this ->_auth ->logout ();
@@ -103,4 +130,22 @@ public function execute()
103130 $ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
104131 return $ resultRedirect ->setPath ("*/*/ " );
105132 }
133+
134+ /**
135+ * Get user modified fields
136+ *
137+ * @param User $user
138+ * @return array
139+ */
140+ private function getModifiedFields (User $ user )
141+ {
142+ $ modifiedFields = [];
143+ $ propertiesToCheck = ['password ' , 'username ' , 'firstname ' , 'lastname ' , 'email ' ];
144+ foreach ($ propertiesToCheck as $ property ) {
145+ if ($ user ->getOrigData ($ property ) !== $ user ->{'get ' . ucfirst ($ property )}()) {
146+ $ modifiedFields [] = $ property ;
147+ }
148+ }
149+ return $ modifiedFields ;
150+ }
106151}
0 commit comments