Skip to content

Commit a97b692

Browse files
committed
Merge remote-tracking branch 'Franciscof-Serfe/improve-success-messages-admin-backend' into AC-10886
2 parents b2b7b32 + bec6533 commit a97b692

File tree

2 files changed

+40
-4
lines changed
  • app/code/Magento/Backend/Controller/Adminhtml/System/Account
  • dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/System

2 files changed

+40
-4
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Framework\Exception\State\UserLockedException;
1313
use 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();

dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/System/AccountTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testSaveAction($password, $passwordConfirmation, $isPasswordChan
7272

7373
public static function saveDataProvider()
7474
{
75-
$password = uniqid('123q');
75+
$password = uniqid('1234q');
7676
return [
7777
[$password, $password, true],
7878
[$password, '', false],

0 commit comments

Comments
 (0)