Skip to content

Commit 41fc278

Browse files
feat: update success message with field changed ref
1 parent 91cb4d4 commit 41fc278

File tree

1 file changed

+26
-1
lines changed
  • app/code/Magento/Backend/Controller/Adminhtml/System/Account

1 file changed

+26
-1
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,32 @@ public function execute()
8181
} else {
8282
$user->save();
8383
$user->sendNotificationEmailsIfRequired();
84-
$this->messageManager->addSuccessMessage(__('You saved the account.'));
84+
85+
// Check which fields were modified after saving
86+
$modifiedFields = [];
87+
$propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email'];
88+
89+
foreach ($propertiesToCheck as $property) {
90+
if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) {
91+
$modifiedFields[] = $property;
92+
}
93+
}
94+
95+
if (!empty($modifiedFields)) {
96+
$countModifiedFields = count($modifiedFields);
97+
$successMessage = '';
98+
// validate how many fields were modified to display them correctly
99+
if ($countModifiedFields > 1) {
100+
$lastModifiedField = array_pop($modifiedFields);
101+
$modifiedFieldsText = implode(', ', $modifiedFields);
102+
$successMessage = __('The %1, and %2 of this account have been modified successfully.', $modifiedFieldsText, $lastModifiedField);
103+
} else {
104+
$successMessage = __('The %1 of this account has been modified successfully.', reset($modifiedFields));
105+
}
106+
$this->messageManager->addSuccessMessage($successMessage);
107+
} else {
108+
$this->messageManager->addSuccessMessage(__('You saved the account.'));
109+
}
85110
}
86111
} catch (UserLockedException $e) {
87112
$this->_auth->logout();

0 commit comments

Comments
 (0)