add-plugin.md 1.8 KB

Read this when adding or changing a discoverable PHP plugin, permission, or menu entry.

Add or Change a Plugin

  1. Use the discovery convention. Create a directory below src/ with an initializer named after the directory. Its namespace must follow the path and the class must extend PluginStrategy.

    namespace Modules\Example;
    
    use Core\System\PluginStrategy;
    
    class Example extends PluginStrategy
    {
       public function __construct()
       {
       }
    }
    
  2. Keep plugin construction safe at boot. ApplicationComposition instantiates every valid plugin after System; configuration, database, and framework globals are then available.

  3. Use persistent numeric permission IDs. Use the existing catalog ID defined by the subsystem, such as permission ID 2 for Inventory Monitor. Permission ID 1 is reserved for administrator authorization.

  4. Register menu entries through AddMenuItem(). Use a numeric permissionId for protected entries. The method publishes entries only when the restored user has the required permission.

    $this->AddMenuItem('Inventory Monitor', ['url' => 'inventory', 'permissionId' => 2]);
    
  5. For API behavior, add routes in Core\Api\Api, not in the new plugin. Follow add-api-endpoint.md.

  6. For an interactive page, add a matching React route and ensure the navigation URL resolves under the application base path. The implemented Inventory Monitor page uses /inventory; frontend route guards are not a substitute for API authorization.

  7. Update documentation. Add the subsystem to module index; create a domain spec only if it introduces a non-obvious data model and business contracts.

See backend conventions and file structure.