plg_webservices_mokowaas: Update event handler for Joomla 6 API #48

Closed
opened 2026-05-26 18:28:06 +00:00 by jmiller · 5 comments
Owner

Summary

The plg_webservices_mokowaas plugin uses the Joomla 4/5 event handler signature, which is incompatible with Joomla 6's typed event system. This breaks the entire Joomla REST API on any site running this plugin on Joomla 6.

Error

Call to undefined method BeforeApiRouteEvent::createCRUDRoutes()

Root Cause

In plugins/webservices/mokowaas/src/Extension/MokoWaaSApi.php, the handler uses the old-style pass-by-reference signature:

public function onBeforeApiRoute(&$router): void

With SubscriberInterface, the first argument is the event object, not the router. So $router is actually a BeforeApiRouteEvent instance, and calling createCRUDRoutes() on it fails.

Fix

Update to use the Joomla 6 typed event API:

use Joomla\\CMS\\Event\\Application\\BeforeApiRouteEvent;

public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
    $router = $event->getRouter();
    $router->createCRUDRoutes(...);
}

Current Status

  • Live server: Hotfixed directly on mokoconsulting.tech (2026-05-26)
  • Dev server: API template fixed, but plugin still has old signature
  • Source repo: Not yet updated — this issue tracks the proper fix

Additional Context

A second issue was also discovered and hotfixed: the api/templates/system/ directory was missing on both live and dev servers. Joomla 6.1's CMSApplication::isValidTemplate() requires api/templates/system/index.php to exist. This should be verified in the deployment/packaging process.

Acceptance Criteria

  • Update MokoWaaSApi.php to use BeforeApiRouteEvent typed parameter
  • Add BeforeApiRouteEvent import
  • Verify api/templates/system/index.php is included in package or deployment
  • Test REST API on dev site after deploying fix
  • Tag a patch release
## Summary The `plg_webservices_mokowaas` plugin uses the Joomla 4/5 event handler signature, which is incompatible with Joomla 6's typed event system. This breaks the entire Joomla REST API on any site running this plugin on Joomla 6. ## Error ``` Call to undefined method BeforeApiRouteEvent::createCRUDRoutes() ``` ## Root Cause In `plugins/webservices/mokowaas/src/Extension/MokoWaaSApi.php`, the handler uses the old-style pass-by-reference signature: ```php public function onBeforeApiRoute(&$router): void ``` With `SubscriberInterface`, the first argument is the **event object**, not the router. So `$router` is actually a `BeforeApiRouteEvent` instance, and calling `createCRUDRoutes()` on it fails. ## Fix Update to use the Joomla 6 typed event API: ```php use Joomla\\CMS\\Event\\Application\\BeforeApiRouteEvent; public function onBeforeApiRoute(BeforeApiRouteEvent $event): void { $router = $event->getRouter(); $router->createCRUDRoutes(...); } ``` ## Current Status - **Live server**: Hotfixed directly on `mokoconsulting.tech` (2026-05-26) - **Dev server**: API template fixed, but plugin still has old signature - **Source repo**: Not yet updated — this issue tracks the proper fix ## Additional Context A second issue was also discovered and hotfixed: the `api/templates/system/` directory was missing on both live and dev servers. Joomla 6.1's `CMSApplication::isValidTemplate()` requires `api/templates/system/index.php` to exist. This should be verified in the deployment/packaging process. ## Acceptance Criteria - [ ] Update `MokoWaaSApi.php` to use `BeforeApiRouteEvent` typed parameter - [ ] Add `BeforeApiRouteEvent` import - [ ] Verify `api/templates/system/index.php` is included in package or deployment - [ ] Test REST API on dev site after deploying fix - [ ] Tag a patch release
jmiller added the joomlaphppriority: hightype: bug labels 2026-05-26 18:28:06 +00:00
Author
Owner

Branch created: feature/48-plg-webservices-mokowaas-update-event-ha

git fetch origin
git checkout feature/48-plg-webservices-mokowaas-update-event-ha
Branch created: [`feature/48-plg-webservices-mokowaas-update-event-ha`](https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/src/branch/feature/48-plg-webservices-mokowaas-update-event-ha) ```bash git fetch origin git checkout feature/48-plg-webservices-mokowaas-update-event-ha ```
Author
Owner

Tracked in moko-platform as MokoConsulting/moko-platform#164

Tracked in moko-platform as MokoConsulting/moko-platform#164
Author
Owner
**Related issues:** - MokoConsulting/MokoWaaS#48 (source — hotfixed on live) - MokoConsulting/moko-platform#164 (tracking) - MokoConsulting/Template-Generic#32 - MokoConsulting/Template-Joomla#13
Author
Owner

Fix Applied

Commit: 3f20ad9 on dev

Changes

src/packages/plg_webservices_mokowaas/src/Extension/MokoWaaSApi.php:

  1. Added import: use Joomla\CMS\Event\Application\BeforeApiRouteEvent;
  2. Updated method signature:
    • Before: public function onBeforeApiRoute(&\): void
    • After: public function onBeforeApiRoute(BeforeApiRouteEvent \): void
  3. Added router extraction: \ = \->getRouter();

Remaining

  • Verify api/templates/system/index.php in package/deployment
  • Test REST API on dev site
  • Tag patch release
## Fix Applied **Commit:** [`3f20ad9`](https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/commit/3f20ad9) on `dev` ### Changes `src/packages/plg_webservices_mokowaas/src/Extension/MokoWaaSApi.php`: 1. Added import: `use Joomla\CMS\Event\Application\BeforeApiRouteEvent;` 2. Updated method signature: - **Before:** `public function onBeforeApiRoute(&\): void` - **After:** `public function onBeforeApiRoute(BeforeApiRouteEvent \): void` 3. Added router extraction: `\ = \->getRouter();` ### Remaining - [ ] Verify `api/templates/system/index.php` in package/deployment - [ ] Test REST API on dev site - [ ] Tag patch release
Author
Owner

Proof

Fixed in commit 3f20ad9 (dev), merged to main via a68e90d.

Changes:

  • Added BeforeApiRouteEvent import
  • Updated onBeforeApiRoute() signature to typed event
  • Router extracted via $event->getRouter()

Workflows also updated (paths filter removed) on both dev and main.

## Proof Fixed in commit 3f20ad9 (dev), merged to main via a68e90d. Changes: - Added BeforeApiRouteEvent import - Updated onBeforeApiRoute() signature to typed event - Router extracted via $event->getRouter() Workflows also updated (paths filter removed) on both dev and main.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoWaaS#48