projet-normandie / article-bundle
Normandie ArticleBundle
Installs: 355
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.3
- a2lix/translation-form-bundle: ~3.0
- api-platform/doctrine-orm: ^4.0
- api-platform/symfony: ^4.0
- doctrine/orm: ^3.3
- sonata-project/admin-bundle: ^4.0
- sonata-project/doctrine-orm-admin-bundle: ^4.8
- stof/doctrine-extensions-bundle: ^1.14
- symfony/dependency-injection: ^6.4 | ^7.2
- symfony/event-dispatcher: ^6.4 | ^7.2
- symfony/http-kernel: ^6.4 | ^7.2
- symfony/security-bundle: ^6.4 | ^7.2
- symfony/validator: ^6.4 | ^7.2
- webmozart/assert: ^1.11
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.5
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-doctrine: ^2.0
- phpstan/phpstan-symfony: ^2.0
- squizlabs/php_codesniffer: ^3.7
- symfony/phpunit-bridge: ^6.4 | ^7.2
This package is auto-updated.
Last update: 2025-05-11 05:23:21 UTC
README
A Symfony bundle for managing multilingual articles with comments, integrated with Sonata Admin and API Platform.
Features
- Multilingual Articles: Full support for multiple languages using A2lix TranslationFormBundle
- Comments System: Allows users to comment on articles with user authentication
- Admin Interface: Complete Sonata Admin integration for managing articles and comments
- API Platform: RESTful API endpoints for articles and comments
- Status Management: Articles can have different statuses (UNDER CONSTRUCTION, PUBLISHED, CANCELED)
- Automatic Slug Generation: Creates SEO-friendly URLs automatically
- Timestamps: Automatic tracking of creation and update times
- User Management: Integration with security system for authors and commenters
Requirements
- PHP 8.3+
- Symfony 6.4+ or 7.0+
- Doctrine ORM
- Sonata Admin Bundle
- API Platform
- A2lix Translation Form Bundle
- Symfony Security Bundle
Installation
- Install the bundle via Composer:
composer require projet-normandie/article-bundle
- Enable the bundle in
config/bundles.php
:
return [ // ... ProjetNormandie\ArticleBundle\ProjetNormandieArticleBundle::class => ['all' => true], ];
- Import the bundle configuration in your
config/packages/
directory.
Configuration
The bundle auto-configures most services. Key services include:
- Admin Classes:
ArticleAdmin
andCommentAdmin
for Sonata Admin - Event Listeners: For articles, article translations, and comments
- API Resources: REST endpoints for articles and comments
- Doctrine Extensions: Translation support for API queries
Usage
Article Management
Articles support multiple languages and three statuses:
use ProjetNormandie\ArticleBundle\Entity\Article; use ProjetNormandie\ArticleBundle\ValueObject\ArticleStatus; $article = new Article(); $article->setStatus(ArticleStatus::PUBLISHED); $article->setTitle('My Article', 'en'); $article->setTitle('Mon Article', 'fr'); $article->setText('Content in English', 'en'); $article->setText('Contenu en français', 'fr');
Using the Article Builder
The bundle provides a builder for creating articles:
$builder = $container->get('pn.article.builder.article'); $builder ->setAuthor($user) ->setTitle('Title', 'en') ->setContent('Content', 'en') ->send();
API Endpoints
The bundle exposes the following REST API endpoints:
Articles
GET /api/articles
- List all articlesGET /api/articles/{id}
- Get a specific articleGET /api/articles/{id}/comments
- Get comments for an article
Comments
GET /api/article_comments
- List all commentsGET /api/article_comments/{id}
- Get a specific commentPOST /api/article_comments
- Create a new comment (requires authentication)PUT /api/article_comments/{id}
- Update a comment (requires ownership)
Admin Interface
Access the admin interface at:
/admin/article/list
- Article management/admin/comment/list
- Comment management
Key Components
Entities
- Article: Main article entity with multilingual support
- ArticleTranslation: Stores translations for articles
- Comment: Comments on articles
- UserInterface: Interface for user integration
Event Listeners
- ArticleListener: Handles author assignment and slug generation
- ArticleTranslationListener: Updates article timestamps on translation changes
- CommentListener: Manages comment count and user assignment
Value Objects
- ArticleStatus: Manages article status values (UNDER_CONSTRUCTION, PUBLISHED, CANCELED)
Translations
The bundle includes translations for:
- English (en)
- French (fr)
Add more languages by creating files in src/Resources/translations/
.
Form Types
- RichTextEditorType: Custom form type for rich text editing
Security
- Creating comments requires
ROLE_USER
- Updating comments requires ownership verification
- Admin access follows Sonata Admin security configuration
Extending the Bundle
Custom User Entity
Configure Doctrine to resolve the interface to your entity in config/packages/doctrine.yaml
:
doctrine: orm: resolve_target_entities: ProjetNormandie\ArticleBundle\Entity\UserInterface: App\Entity\User # or your User entity namespace
Or if you're using another bundle:
doctrine: orm: resolve_target_entities: ProjetNormandie\ArticleBundle\Entity\UserInterface: ProjetNormandie\UserBundle\Entity\User
License
This bundle is open-source software licensed under the MIT license.
Support
For issues and feature requests, please use the GitHub issue tracker.
Credits
Developed by Projet Normandie team.