Problem/Motivation

The bee_hotel module currently implements its own token system for guest messages. Tokens are defined in YAML files under config/guest_messages and replaced with a simple str_replace() call. While functional, this approach bypasses Drupal's native Token API and isolates BeeHotel tokens from the rest of the Drupal ecosystem.

Guest messages are one of the most valuable features of BeeHotel for small hospitality businesses. A B&B owner or a small hotel manager can prepare a message template once — a booking confirmation, a pre-arrival welcome, a check-out reminder, a review request — and have it automatically personalised for every guest with their name, booking number, room, dates, balance due, and bank details. No manual copy-paste, no risk of sending the wrong guest the wrong dates. Examples of everyday use cases:

  • Booking confirmation. "Dear [guest name], thank you for your booking no. [booking number]. Your arrival is expected on [arrival date], room [room name], total [total amount], balance due [balance]." Sent automatically in the guest's language.
  • Pre-arrival welcome. "We look forward to welcoming you on [arrival date]. Check-in is available from [checkin time]. Here are the directions and the Wi-Fi password."
  • Balance reminder. "Your balance of [balance] is due by [balance due date]. Bank details: [bank details]."
  • Check-out reminder. "Check-out is by [checkout time] on [checkout date]. Thank you for staying with us."
  • Post-stay review request. "Dear [guest name], we hope you enjoyed your stay in [room name]. Would you leave us a review?"

These messages are sent by email or WhatsApp directly from the order page, in the guest's own language, with attachments and useful links (maps, directions, house rules). This is what makes BeeHotel usable by non-technical property owners: they write the message once, in plain language, and BeeHotel fills in the details for each guest.

However, the current token system — described in the next paragraph — limits this value. Because BeeHotel tokens are not registered with Drupal's Token API, they cannot be used outside the guest-message context, they cannot be chained with entity tokens, and they cannot be picked up by other modules or by the standard token browser. Aligning BeeHotel with the standard Token API would make guest messages more powerful, more reliable, and easier to extend for the property owner.

Proposed resolution

Migrate the guest-message token layer to Drupal's standard Token API.

  1. Define token types and tokens via hook_token_info() (or the #[Hook] attribute in Drupal 11.2+).
  2. Implement replacement logic in hook_tokens(), using $bubbleable_metadata to declare cache dependencies.
  3. Replace the custom str_replace() loop in BeeHotelGuestMessageTokens::applyTokens() with \Drupal::token()->replace().
  4. Keep the YAML files only for message templates, removing them from the token definition role.

This change can be rolled out progressively: new standard tokens can coexist with the legacy [token_id] syntax until all stored messages are migrated.

Issue fork bee_hotel-3634496

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

afagioli created an issue. See original summary.

afagioli’s picture

Issue summary: View changes
afagioli’s picture

Issue summary: View changes

  • afagioli committed 78ba8f80 on 2.28.x
    Issue #3634496: Adopt Drupal Token API for guest messages
    
    - Add...

shubhamgoel made their first commit to this issue’s fork.

shubhamgoel’s picture

Status: Active » Needs review
afagioli’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

shubhamgoel’s picture

Hi team,

Can you please review the contribution record?

afagioli’s picture

The implemented code is working with no evidence of bugs

afagioli’s picture

Hi shubhamgoel,

Thank you for your contribution on this issue. Even though the merge request !11 ended with a merge error, your work was constructive and helped move the resolution of #3634496 forward. The effort you put into the MR (including the revert and the subsequent adaptation commit) gave us a solid basis to evaluate and finalise the Token API integration.

Your name has been mentioned in the contribution record for this issue, acknowledging the work you did here.

Please keep submitting merge requests to the BEE Hotel project — contributions like yours are important for the growth of the module and the community around it. We look forward to seeing more from you.

Thanks again,

shubhamgoel’s picture

Thanks @afagioli,

Happy to contribute.