As you can see in CrudController, when the update action is successful, for every entity, this code is run : https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L357 :
$this->addFlash(
'sonata_flash_success',
$this->trans(
'flash_edit_success',
['%name%' => $this->escapeHtml($this->admin->toString($existingObject))],
'SonataAdminBundle'
)
);
So if you want to overide it :
Solution 1 :
You change de translation for every entities...
Solution 2:
You overide this flash message in using your own controller specific to UserEntity...
If I was you, I'll create a baseController, in order to make this translation customizable, and every entity will herit from this....
UPDATE :
In the baseController, you override each actions (create, delete, edit).
After you've got the choise, the first : you create a custom action, the second, you create a protected variable for translation message ...
class OwnBaseController extends BaseController {
....
protected $successMessage = "flash_edit_success";
protected $errorMessage = "flash_edit_error";
....
/** Exemple with edit action **/
try {
$existingObject = $this->admin->update($submittedObject);
if ($this->isXmlHttpRequest()) {
return $this->renderJson([
'result' => 'ok',
'objectId' => $objectId,
'objectName' => $this->escapeHtml($this->admin->toString($existingObject)),
], 200, []);
}
$this->addFlash(
'sonata_flash_success',
$this->successMessage , // <----- LOOK HERE
'messages'
)
);
// redirect to edit mode
return $this->redirectTo($existingObject);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$isFormValid = false;
} catch (LockException $e) {
$this->addFlash('sonata_flash_error', $this->trans($this->errorMessage, [ // <----- LOOK HERE
'%name%' => $this->escapeHtml($this->admin->toString($existingObject)),
'%link_start%' => '<a href="'.$this->admin->generateObjectUrl('edit', $existingObject).'">',
'%link_end%' => '</a>',
], 'SonataAdminBundle'));
}
class UserController extends OwnBaseController {
protected $successMessage = "user_edit_success_custom_message";
protected $errorMessage = "user_edit_error_custom_message";
}