This blog outlines my experience creating a welcome message to the current website user using three approaches in a Drupal 8 module. The first approach is to have the user name pulled out of Drupal currentUser and displayed on the website with the welcome message. This message is displayed only when the user signs in to the website; it disappears altogether when the user moves away from the home page. One way to keep the message on the site even when the user moves away from the home page is to create a Welcome link on the main menu so that when the link is clicked, the welcome message appears on the front page.The second approach is to create a block and have the currentUser name pulled out using Dependency Injection and displayed with the message. The block will be a permanent fixture on the website and remains on the site at all times.The third method is to download the Token module from Drupal.org and use that to add the currentUser to the message. The message is placed in a block on the front page. The block can also be configured and edited to change the message to whatever you want before it is posted to the front page.I attach a few screen captures.
- one showing the welcome message with the user name when the user logs in; this message disappears when the user moves away from the home page.
- the second one shows the welcome message first as a link on the main menu and as a block that can be edited to say whatever you wish. When the Welcome link on the main menu is clicked, the welcome message appears.
This screen capture shows the welcome message when the user logs in, and on the left sidebar as a block
This screen capture shows the welcome message when the user logs in, and on the left sidebar as a block |
This screen capture shows the welcome message when the user clicks on the Welcome tab; the message also appears on the left sidebar as a block
This screen capture shows a configuration form which is editable; the message can be put in this form, saved, and called up in a block which is placed on a sidebar
This screenshot shows a message in a block placed in the left sidebar with the name of the user.; a welcome message is also shown when the Welcome tab is clicked.
This screen capture shows a configuration form which is editable; the message can be put in this form, saved, and called up in a block which is placed on a sidebar |
This screenshot shows a message in a block placed in the left sidebar with the name of the user.; a welcome message is also shown when the Welcome tab is clicked. |
No comments:
Post a Comment