Office Hours widget removes warning messages from other modules (e.g. Content Lock)

Created on 24 July 2025, 10 days ago
Updated 26 July 2025, 8 days ago

Problem/Motivation

I've discovered an issue where the Office Hours module is removing unrelated warning messages, specifically from the Content Lock module, when using the office_hours widget.

The culprit appears to be this line in OfficeHoursComplexWeekWidget.php:
\Drupal::messenger()->deleteByType(static::MESSAGE_TYPE);
This clears all warning messages (MessengerInterface::TYPE_WARNING) at the end of formElement(), even those not generated by Office Hours itself.

Steps to reproduce

  • User A opens a content item for editing — this creates a lock via the Content Lock module.
  • User B opens the same content item while User A still has it locked.
  • Expected: Two warning messages should appear for User B:
    • A message stating the content is locked.
    • A message with a link to break the lock.
  • Actual: These messages are missing if the content item contains a field using the office_hours widget.

Temporary Fix

I commented out this line:
// \Drupal::messenger()->deleteByType(static::MESSAGE_TYPE);
With this change, messages from content_lock displays correctly again.

Proposed resolution

Office Hours should track only the messages it adds, for example by storing them in a static class property or a dedicated service. It could then provide a helper method such as clearOwnMessages() to remove only those specific messages from the messenger service. This would avoid relying on deleteByType(), which clears all messages of a given type and should be used only when absolutely necessary.

Thanks for maintaining this module.

🐛 Bug report
Status

Active

Version

1.0

Component

Code - widget

Created by

🇺🇸United States bfetner

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.

Production build 0.71.5 2024