Problem/Motivation
drupal_set_message() accepts a $type parameter (string) that may be one of:
The logging system, on the other hand, defines a different set of severities. Per Drupal\Core\Logger\RfcLoggerTrait, these include:
- emergency
- alert
- critical
- error
- warning
- notice
- info
- debug
To facilitate such features as automatic logging of messages (see, for example,
β¨
drupal_set_message('whatever', 'error') should be integrated with logging
Postponed: needs info
), these should be harmonized.
Proposed resolution
Both drupal_set_message() and the logging system should use the same values for their 'severity' or 'type' parameters for consistency. Likely this means that:
- drupal_set_message() should accept, as $type, an RfcLogLevel::* constant (though this seems to be a somewhat inappropriate use of RfcLogLevel since user messages have nothing to do, logically, with logging); or,
- drupal_set_message() should be entirely refactored into a some sort of 'UserMessage' service. This is already in consideration but postponed to 8.1.x at
#2278383: Create an injectible service for drupal_set_message() β
Of course, drupal_set_message() is also on the path to obliteration altogether, per
#2073817: [META] Remove drupal_set_message() β
and so this debate may be moot once postponed to 8.1.x.
Remaining tasks
As noted above, it is not yet clear precisely how this should be implemented, if it should be implemented at all. Further discussion about the merits of this change is required.
Postponing to 8.1.x because this is not needed to resolve a bug or issue prior to 8.x release. Implementation #1 above could likely be made without breaking backwards compatibility (by testing $type to determine if it is a string or an RfcLoggerTrait constant), but this is nonetheless an API change that is hardly critical to 8.x. Implementation #2 is clearly beyond the scope of a change at this stage. If this route is deemed advisable
User interface changes
Not yet determined.
API changes
Not yet entirely determined, but clearly this would require a change to the drupal_set_message() function to harmonize the 'levels'.
Beta phase evaluation
<!--Uncomment the relevant rows for the issue. -->