Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

News Bundle Laravel Package

rmzamora/news-bundle

rmzamora/news-bundle is a Laravel/PHP package for adding news features to your application. It helps developers organize and publish news content, offering a simple starting point for building news, blog, or article sections without heavy setup.

View on GitHub
Deep Wiki
Context7

Getting Started

This package is the rmzamora fork of sonata-project/news-bundle, a Sonata Admin–based news/blog bundle for Symfony. It is archived and unmaintained (0 stars, 0 dependents), so treat it as a legacy codebase you inherit rather than a dependency you adopt. Before installing, open the fork's composer.json and confirm the PHP and Symfony constraints — the fork pins an era of Symfony (likely 2.x/3.x), and Composer will refuse to resolve it against a modern application.

Minimal path:

  1. composer require rmzamora/news-bundle (add the repository/VCS entry if it is not on Packagist).
  2. Register the bundle alongside its hard dependencies: SonataAdminBundle, SonataDoctrineORMAdminBundle, SonataBlockBundle, and SonataClassificationBundle (used for tags/collections). Without these, admin routes and blocks silently fail to render.
  3. Import the bundle's routing (Resources/config/routing/*.xml) — the front controllers (news, news_view, news_feed, comment create) and admin routes are separate files.
  4. Dump the config reference (bin/console config:dump-reference sonata_news) and create a sonata_news.yaml with at least title, link, salt, per_page, and the entity class mapping.
  5. Configure the entity classes — either use the bundle's own Entity/News, NewsCategory, NewsComment, or map your extended subclasses under sonata_news.class.news etc. Run doctrine:schema:update/migrations.
  6. Load fixtures or create a post in the Sonata Admin dashboard.

Where to look first: Entity/ and Document/ (mapping and getSalt()), Admin/NewsAdmin.php (form fields, batch actions), Resources/config/admin.xml and Resources/config/routing/ (service IDs and route names), Block/ (recent posts, archive, RSS blocks), and Controller/NewsController.php + Controller/NewsFeedController.php (front-end behavior).

First use case: publish a News item with a category and publicationDateStart in the past, confirm it appears at the configured /news list route and in the RSS feed, then drop {{ sonata_block_render({ 'type': 'sonata.news.block.recent_posts' }) }} into a layout to verify block wiring.

Implementation Patterns

  • Extend, don't edit. The canonical Sonata pattern: subclass BaseNews/BaseNewsCategory, keep the bundle untouched, and point sonata_news.class.* config at your classes. Same for Admin/NewsAdmin: subclass it, change configureFormFields()/configureDatagridFilters(), and override the sonata.admin.news service definition (or use sonata.admin.extension for additive changes).
  • Permalinks. The default NewsPermalinkGenerator builds a dated slug route (sonata_news_view). If you need SEO-friendly or localized URLs, implement the permalink generator interface and replace the sonata.news.permalink.generator service.
  • Query service, not repository in controllers. Use sonata.news.manager.news (NewsManagerInterface) with findLatest, findByCategory, findByDateRange, and the pager helpers. Front-end controllers are thin and easy to copy if you need custom actions.
  • Blocks are the integration surface. Recent-posts, archive, and RSS blocks are registered as Sonata block services; render them from Twig with sonata_block_render. If you need a different query, extend the block service and re-register the service ID.
  • Template overrides. Standard Symfony bundle override path (templates/bundles/SonataNewsBundle/... on Flex, app/Resources/SonataNewsBundle/views/... on older apps). The feed template and list/item partials are the ones you'll touch most.
  • Comments. Enable in sonata_news.comment and use the comment-create route from your item template. The comment hash is validated against the configured salt. Moderation happens through NewsCommentAdmin.
  • Cross-bundle wiring. Categories come from NewsCategory while free-form tags/collections typically come from SonataClassificationBundle; make sure the admin form context is configured for both or you get missing-field errors on save.
  • Dependency injection for content rendering. Content is rendered through Sonata's formatter/block helpers; verify SonataFormatterBundle (or equivalent) is installed if you expect rich HTML and markdown, otherwise you'll store and output raw strings.

Gotchas and Tips

  • Archived = frozen. No security patches, no Symfony upgrade path, and no upstream fixes. Vendor-patch (patches in composer or a local src/ bundle) and pin every transitive Sonata dependency. Do not start greenfield work on this.
  • The comment salt is load-bearing. News::getSalt() returns the configured salt; changing sonata_news.comment.salt invalidates every previously generated comment hash and breaks existing threads. Set it once, keep it in env, never rotate casually.
  • publicationDateStart drives visibility. Feeds and list blocks filter on it, not createdAt. A post saved without a publication date silently disappears from blocks and RSS even though it exists in admin.
  • Permalinks are not immutable by default. Editing the title after publish changes the generated permalink and breaks inbound links. Add a redirect or lock the slug at persist time.
  • Entity mapping churn. Switching from the bundle's default entities to your subclasses generates a full schema diff (inheritance strategy dependent). Decide before you have production data, and expect a migration on the switch.
  • Route name collisions. The bundle registers generic names (news, news_view, news_feed); importing them at the app root can clash. Prefix or import under a scope.
  • Block caching. Blocks are cached via sonata_block config; new posts may not appear until TTL expiry. Lower the TTL in dev and verify with the block cache disabled when debugging "missing post" reports.
  • Debugging entry points: bin/console debug:router | grep sonata_news, debug:container sonata.news.manager.news, and debug:container --tag=sonata.block will resolve most wiring confusion faster than reading the archived README.
  • Extension points worth knowing: admin prePersist/preUpdate for slug/date normalization, a custom NewsManager to centralize published-only queries, and the block service layer for anything you'd otherwise hack into templates.
  • Fork hygiene. If you must maintain it, re-publish under your own namespace with an explicit minimum-stability entry; relying on the archived VCS URL means a future branch deletion breaks your build with no fallback.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource