{"record":{"id":"653b28d79fe94304","repo":"flarum/framework","slug":"the-entity-must-use-the-eventgeneratortrait-trait-in-order","errorCode":null,"errorMessage":"The entity must use the EventGeneratorTrait trait in order to dispatch events.","messagePattern":"The entity must use the EventGeneratorTrait trait in order to dispatch events\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/core/src/Foundation/DispatchEventsTrait.php","lineNumber":22,"sourceCode":" * This file is part of Flarum.\n *\n * For detailed copyright and license information, please view the\n * LICENSE file that was distributed with this source code.\n */\n\nnamespace Flarum\\Foundation;\n\nuse Flarum\\User\\User;\n\ntrait DispatchEventsTrait\n{\n    /**\n     * Dispatch all events for an entity.\n     */\n    public function dispatchEventsFor(mixed $entity, ?User $actor = null): void\n    {\n        if (! method_exists($entity, 'releaseEvents')) {\n            throw new \\InvalidArgumentException(\n                'The entity must use the EventGeneratorTrait trait in order to dispatch events.'\n            );\n        }\n\n        foreach ($entity->releaseEvents() as $event) {\n            if (property_exists($event, 'actor') && ! $event->actor) {\n                $event->actor = $actor;\n            }\n\n            $this->events->dispatch($event);\n        }\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":36,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Foundation/DispatchEventsTrait.php#L4-L36","documentation":"Programming-error guard in DispatchEventsTrait::dispatchEventsFor: the trait releases queued events via $entity->releaseEvents(), which only exists when the entity uses EventGeneratorTrait. Passing an entity without that trait (missing method 'releaseEvents') means its events can never be collected, so an InvalidArgumentException is thrown at development time rather than silently dropping events.","triggerScenarios":"Thrown at framework/core/src/Foundation/DispatchEventsTrait.php:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the EventGeneratorTrait to the entity class","Ensure you are passing the intended model, not a DTO or wrong object","Do not call dispatchEventsFor on entities that never raise domain events"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}