Search by

stijnhau / forum-bundle

stijnhau

Forum (categories, topics, posts, moderation) and its admin for Symfony apps.

Package info

github.com/stijnhau/forum-bundle

Type:symfony-bundle

pkg:composer/stijnhau/forum-bundle

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-11-28 19:31 UTC

This package is auto-updated.

Last update: 2026-11-28 19:32:50 UTC


README

The forum and its admin, shared by CityWars, Crime-Life and F1Manager: categories, topics, posts, moderation (edit/remove with history, delete), and category management.

What's in the box:

Piece What it does
Model\Abstract* Doctrine mapped superclasses for category, topic and post. The app maps a concrete subclass of each, so table names stay the app's and it can add columns (an owning alliance, say).
Service\Forum Start a topic, reply, edit/remove a post (moderators), delete a topic or reply. Every rule lives here; refusals are ForumExceptions.
Service\CategoryAdmin The admin: list, create, edit, reorder and delete (only if empty) the public categories.
Query\ForumReader The reads: public categories with topic counts, a category's topics a page at a time, a topic's posts a page at a time.
Service\ContentPolicy The title/body/category checks plus sanitizing, for an app's own private sub-forums to reuse.
Twig UI (optional) Server-rendered forum and admin pages (ui.enabled: true).

JSON/SPA apps keep their own thin controllers and shape the JSON themselves, on top of Forum, CategoryAdmin and ForumReader.

Install

composer require stijnhau/forum-bundle

Register Stijnhau\ForumBundle\StijnhauForumBundle::class => ['all' => true] in config/bundles.php.

Wire it up

  1. The user entity implements Stijnhau\ForumBundle\Model\ForumUserInterface (getId(), getForumDisplayName(), isForumModerator()).

  2. Map the three entities:

    #[ORM\Entity]
    class ForumCategory extends AbstractForumCategory {}
    #[ORM\Entity]
    class ForumTopic extends AbstractForumTopic {}
    #[ORM\Entity]
    class ForumPost extends AbstractForumPost {}
  3. Configure config/packages/stijnhau_forum.yaml:

    stijnhau_forum:
        user_class: App\Entity\User
        category_class: App\Entity\ForumCategory
        topic_class: App\Entity\ForumTopic
        post_class: App\Entity\ForumPost
        per_page: 20                       # posts/topics per page
        body_max_length: 4000              # sanitized HTML length
        authors_may_delete: false          # may authors delete their own topics/replies?
        category_description_required: true
        ui:
            enabled: false                 # the Twig pages below
            admin_role: ROLE_ADMIN
  4. bin/console make:migration. The bundle ships no migrations; the schema belongs to the app.

Hooks

  • Who may post: implement Security\PostingGuardInterface (mutes, bans, rate limits). Every implementation is picked up automatically and runs before each new topic and reply. Throw to refuse.

  • Private sub-forums: if the category table also holds private categories (an alliance's own, say), implement Scope\ForumScopeInterface and alias it:

    services:
        Stijnhau\ForumBundle\Scope\ForumScopeInterface: '@App\Forum\PublicForumScope'

    Public lookups, listings and every Forum/CategoryAdmin action then treat those categories as missing.

  • Events: TopicCreatedEvent, PostCreatedEvent, PostEditedEvent, PostRemovedEvent, TopicDeletedEvent and PostDeletedEvent, each carrying the actor, topic and post. isByAuthor() tells moderation apart from self-service, for a moderation log, say.

  • Errors: ForumException::getKey() is a key in the stijnhau_forum translation domain (en/nl/fr ship with the bundle). $e->trans($translator) gives the text.

Twig UI

With ui.enabled: true, import the routes:

# config/routes/stijnhau_forum.yaml
stijnhau_forum:
    resource: '@StijnhauForumBundle/config/routes.php'
    prefix: /forum
    trailing_slash_on_root: false
stijnhau_forum_admin:
    resource: '@StijnhauForumBundle/config/routes_admin.php'
    prefix: /admin/forum
    trailing_slash_on_root: false

Every page requires a logged-in ForumUserInterface; the admin pages also require ui.admin_role. To plug the pages into your layout, override templates/bundles/StijnhauForumBundle/forum/layout.html.twig (keep the forum_title and forum blocks) and .../admin/layout.html.twig (keep forum_title and forum_admin). You can override any other template the same way. The body field carries data-forum-editor for hooking up a rich-text editor. Without JavaScript, plain text is turned into paragraphs.

Development

composer install
vendor/bin/phpunit

License

MIT, see LICENSE.