Skip to content

Commit c635173

Browse files
committed
apply suggestions
* update the structure for better read and understanding
1 parent 812c0e1 commit c635173

1 file changed

Lines changed: 32 additions & 28 deletions

File tree

docs/design/flash_messages.rst

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,52 @@ Implementing flash messages
33

44
Flash messages are temporary notifications that appear at the top of the page to inform users about the result of an action.
55

6-
Backend (PHP) implementation
6+
Backend implementation - PHP
77
****************************
88

9-
Add your translation strings to ``{bundle}/Translations/en_US/flashes.ini``:
9+
#. Add translation strings to ``{bundle}/Translations/en_US/flashes.ini``.
10+
#. Use the following code in your controllers:
1011

11-
**In controllers:**
12+
.. code-block:: php
1213
13-
.. code-block:: php
14+
// Success message
15+
$this->addFlashMessage('mautic.core.notice.created', [
16+
'%name%' => $entity->getName()
17+
]);
1418
15-
// Success message
16-
$this->addFlashMessage('mautic.core.notice.created', [
17-
'%name%' => $entity->getName()
18-
]);
19+
// Error message
20+
$this->addFlashMessage('mautic.core.error.generic', [], 'error');
1921
20-
// Error message
21-
$this->addFlashMessage('mautic.core.error.generic', [], 'error');
22+
The ``addFlashMessage()`` method accepts three parameters:
2223

23-
The first parameter is the translation key, the second is an array of parameters for the translation, and the third is the message type (default is ``notice``).
24+
* **Translation key**: the unique string identifier from your ``.ini`` file. For example, ``mautic.core.notice.created``.
25+
* **Parameters**: an array of values that replace placeholders - such as ``%name%`` - within the translation string.
26+
* **Message type**: the type of message to display. The default is ``notice``.
2427

25-
Frontend (JavaScript) implementation
28+
Frontend implementation - JavaScript
2629
************************************
2730

28-
Add your translation strings to ``{bundle}/Translations/en_US/javascript.ini``:
31+
#. Add translation strings to ``{bundle}/Translations/en_US/flashes.ini``:
2932

30-
.. code-block:: ini
33+
.. code-block:: ini
3134
32-
mautic.core.notice.my_success_message="Success message here!"
33-
mautic.core.error.my_error_message="Error message here!"
35+
mautic.core.notice.my_success_message="Success message here!"
36+
mautic.core.error.my_error_message="Error message here!"
3437
35-
Create the flash message using one of these helper functions:
36-
- Mautic.addFlashMessage(message) - Generic flash message
37-
- Mautic.addInfoFlashMessage(message) - Info/success flash message
38-
- Mautic.addErrorFlashMessage(message) - Error flash message
38+
#. Create the flash message using one of these helper functions:
3939

40-
Pass the result to Mautic.setFlashes() to display it.
40+
* ``Mautic.addFlashMessage(message)``: creates a generic flash message.
41+
* ``Mautic.addInfoFlashMessage(message)``: creates an info or success flash message.
42+
* ``Mautic.addErrorFlashMessage(message)``: creates an error flash message.
4143

42-
.. code-block:: javascript
44+
#. Pass the result to ``Mautic.setFlashes()`` to display the message.
4345

44-
var message = Mautic.translate('mautic.core.notice.my_success_message');
45-
var flashMessage = Mautic.addInfoFlashMessage(message);
46-
Mautic.setFlashes(flashMessage);
46+
.. code-block:: javascript
4747
48-
var message = Mautic.translate('mautic.core.error.my_error_message');
49-
var flashMessage = Mautic.addErrorFlashMessage(message);
50-
Mautic.setFlashes(flashMessage);
48+
// Display a success message
49+
var successMsg = Mautic.translate('mautic.core.notice.my_success_message');
50+
Mautic.setFlashes(Mautic.addInfoFlashMessage(successMsg));
51+
52+
// Display an error message
53+
var errorMsg = Mautic.translate('mautic.core.error.my_error_message');
54+
Mautic.setFlashes(Mautic.addErrorFlashMessage(errorMsg));

0 commit comments

Comments
 (0)