"status_messages"-like render element with a preset message

Created on 10 March 2017, about 8 years ago
Updated 31 March 2025, about 1 month ago

Problem/Motivation

The "status_messages" render element (\Drupal\Core\Render\Element\StatusMessages) comes with nice CSS. We want to reuse its look when we display warning and/or error messages in the middle long forms, like this:

Unfortunately, "status_messages" is only for displaying messages set by the \drupal_set_message method. That means that it will be displaying all kinds of system messages in a place where we only want our custom message. Instead, we would like an element that displays only the warning/error message that we directly set in its render array.

Proposed resolution

Create a new render element for a such a message box.
e.g., named "message" with properties "#message" and "#style". "#message" is the message that is to be displayed in the box. "#style" can be either "status", "warning", or "error" and determines the appearance.

Or extend "container" with this functionality. (Add optional "#style" property.)

Or make it possible to set "status_messages" to only display messages included in the form array.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

11.0 🔥

Component

render system

Created by

🇨🇭Switzerland VladimirMarko

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    Just ran into the same need (and ran into it in the past several times). I think at least #21 is not good UX and mabe we should simply have a
    '#type' => 'status_messages', render array type to wrap that in a better way?

    Definitely a +1 to have a render array type for status message(s)!

Production build 0.71.5 2024