Skip to content

Modernize event system: drop deprecated cboxpost, keep `user_chatbox_post_created #2

@Jimmi08

Description

@Jimmi08

Background

The plugin currently triggers two events when a message is posted
(chatbox_menu.php, lines 123–125):

$e_event->trigger('cboxpost', $edata_cb); // deprecated
e107::getEvent()->trigger('user_chatbox_post_created', $edata_cb);

This is a half-finished migration inherited from the upstream chatbox_menu
plugin. The new event name user_chatbox_post_created follows e107's
event naming convention (user_<plugin>_<thing>_<verb_past> for
user-initiated actions, admin_<plugin>_<thing>_<verb_past> for
admin-initiated actions). The trigger site was updated, but e_notify.php
still registers the old cboxpost name as the canonical event, so the new
event was never reachable through the admin Notify UI.

Decision

Single canonical event, drop the deprecated alias.

  • Keep: user_chatbox_post_created
  • Remove: cboxpost

Why hard break

The README is clear that this fork is a clean break, not a drop-in
replacement ("It is intended for new installs only and shares no markup,
class names, or upgrade path with the original chatbox_menu plugin"
).
Maintaining cboxpost as a deprecated alias adds noise for no real
benefit: listeners on the original chatbox_menu plugin are bound to that
plugin's namespace, and existing notify configurations from the old plugin
do not carry over.

Changes

chatbox_menu.php

Replace the two trigger() calls with the canonical one:

e107::getEvent()->trigger('user_chatbox_post_created', $edata_cb);

Also drop the global $e_event; declaration earlier in the function — the
modern e107::getEvent() accessor is already used on the next line, so the
older global variable is redundant.

e_notify.php

  • Remove the commented-out legacy notify_cboxpost() function block
    (~10 lines of dead code at the top of the file).
  • Update the config() registration:
  $config[] = array(
      'name'     => NT_LAN_CB_2,
      'function' => "user_chatbox_post_created",
      'category' => ''
  );
  • Rename the handler method cboxpost($data) to
    user_chatbox_post_created($data).
  • Update the $this->send('cboxpost', ...) call inside that method to
    $this->send('user_chatbox_post_created', ...).

Database side effect

Existing installs may have a stale cboxpost entry in notify_prefs from
the original chatbox_menu plugin. After this change, that entry becomes
dormant (nothing triggers cboxpost anymore) and is no longer
configurable through the admin UI. The new user_chatbox_post_created
event will register cleanly on next visit to the admin Notify page.

Users can either ignore the dormant cboxpost entry or remove it manually
from notify_prefs. This migration noise affects only sites that
previously had chatbox_menu installed; fresh installs are unaffected.

Out of scope (follow-up issues)

These belong in their own tickets but are worth noting now so the picture
of the plugin's event surface is documented:

  • Admin moderation events: chat.php provides moderation controls
    (delete / block / unblock messages) that currently do not trigger any
    events. Following the same convention, these would become
    admin_chatbox_post_deleted, admin_chatbox_post_blocked, and
    admin_chatbox_post_unblocked. Useful for audit logging, statistics, or
    notifying users that their post was moderated.
  • Notify message body cleanup: the NT_LAN_CB_* constants and the HTML
    inside the notify message body can be revisited as part of the broader
    markup cleanup pass.

Related

This issue surfaced while testing #N (template system split). A stale
notify_prefs entry referencing the original chatbox_menu_notify class
caused fatal errors on message post. The class lookup error is a separate
e107 core robustness issue (filed upstream: [link to e107inc/e107 issue
once created]) — even after this rename, e107 should not fatal when a
notify handler points at a missing class.

Verification

After the rename:

  • Posting a message must not fatal.
  • The user_chatbox_post_created event appears in the Notify admin
    configurable list.
  • Test event from the Notify admin page fires successfully.
  • A handler registered via e_event.php → register('user_chatbox_post_created', ...)
    in another plugin receives the event.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions