Search by

stijnhau / news-bundle

stijnhau

News and announcements for Symfony apps: posts with optional translations, a publish/expiry window, admin-only writing (via stijnhau/moderation-bundle) and optional ready-made pages.

Package info

github.com/stijnhau/news-bundle

Type:symfony-bundle

pkg:composer/stijnhau/news-bundle

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-28 21:10 UTC

This package is auto-updated.

Last update: 2026-11-28 21:45:40 UTC


README

News and announcements for Symfony apps, shared by CityWars, Crime-Life and F1Manager. Posts can have translations and a publish/expiry window, so one post works as a news item or as a time-boxed banner. Only admins may write. It builds on stijnhau/moderation-bundle: authors are its users, isAdmin() decides who may write, and every change goes in its audit log.

Piece What it does
Model\AbstractNewsPost Doctrine mapped superclass: title, body, translations (locale => title/body), author, published at (future = scheduled), expires at, created and updated times.
Service\NewsAdmin publish(), update(), delete(): admins only, with every rule; bodies sanitized (body_format: html) or kept as plain text.
Query\NewsReader Live posts newest first (paged, or all of them for a banner), all posts for the admin, findLive().
Twig UI (optional) /news and an admin (list, write, edit, delete) with ui.enabled: true.

Install

composer require stijnhau/news-bundle

Register and configure stijnhau/moderation-bundle first (its user_class is the news authors' class), then:

#[ORM\Entity]
class NewsPost extends AbstractNewsPost {}
stijnhau_news:
    post_class: App\Entity\NewsPost
    per_page: 10
    body_format: html             # html (sanitized) or text
    body_max_length: 20000
    sanitizer: ~                  # an HtmlSanitizerInterface service id
    locales: [fr, nl]             # translations a post may have
    audit_log: true               # the moderation bundle's audit log
    actions: { published: news.published, updated: news.updated, deleted: news.deleted }
    ui:
        enabled: false
        admin_role: ROLE_ADMIN

Then run bin/console make:migration.

With the UI enabled, import the routes:

stijnhau_news:
    resource: '@StijnhauNewsBundle/config/routes.php'
    prefix: /news
    trailing_slash_on_root: false
stijnhau_news_admin:
    resource: '@StijnhauNewsBundle/config/routes_admin.php'
    prefix: /admin/news
    trailing_slash_on_root: false

To use your own layout, override templates/bundles/StijnhauNewsBundle/news/layout.html.twig (keep the news_title and news blocks) and admin/layout.html.twig (keep news_title and news_admin). Body fields carry data-news-editor for a rich-text editor.

Errors are NewsExceptions, with keys in the stijnhau_news domain (en/nl/fr included). A NewsChangedEvent is dispatched for every change.

License

MIT, see LICENSE.