Problem/Motivation
At the time of writing, FormHelperTrait::addWarning()
contains this which creates a warning message manually via raw markup and directly attaches the Classy message library.
protected function addWarning($message, $tokens) {
$warning = $this->t($message, $tokens);
$this->form()['warning'] = [
'#type' => 'markup',
'#weight' => -10,
'#markup' => Markup::create("
<div class='messages messages--warning'>
{$warning}
</div>
"),
];
$this->form()['#attached']['library'][] = 'classy/messages';
return $this;
}
This is both unnecessary and prevents the expected Drupal rendering, alter hooks/preprocess, and other things correctly interacting with it. Additionally,
the Classy theme is deprecated in Drupal 9.5 and removed in Drupal 10 →
.
Steps to reproduce
Try to apply any customizations (e.g. preprocess) to warning messages; they won't be applied to the warning message FormHelperTrait::addWarning()
creates. Run this on Drupal 10 without the contrib Classy installed; the status message will no longer have the expected styling.
A minor example on Drupal 9.5 using Claro without the change:
Notice the icon is not placed where it should be and not the correct Claro icon.
With the change:
Notice that it now uses the correct Claro icon and positions it where it should be.
Proposed resolution
In
#3008741-5: Fix readonly notice message styling →
for the Read only mode module, I changed a similar markup output to '#theme' => 'status_messages'
which follows Drupal best practices and allows current and future modules and themes to behave as expected.
Remaining tasks
Do the above.
User interface changes
None?
API changes
None?
Data model changes
None?