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 OpenMind\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. Register permissions before relying on them. Add role names to UserRoles in the plugin constructor. User administration accepts only roles in this registry.

    (new UserRoles())->add('example');
    
  4. Register menu entries through AddMenuItem(). Use permissionName for protected entries. The method publishes entries only when the restored user has the required role.

    $this->AddMenuItem('Example', ['url' => 'example', 'permissionName' => 'example']);
    
  5. For API behavior, add routes in OpenMind\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. 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.