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.