movingimage / mi-comments-bundle
Symfony bundle that provides commenting functionality (posting, reading and administering comments)
Installs: 125
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
- doctrine/doctrine-bundle: ^1.8
- doctrine/doctrine-migrations-bundle: ^1.3
- doctrine/orm: ^2.6
- friendsofsymfony/rest-bundle: ^2.2
- jms/serializer-bundle: ^2.1
- sonata-project/admin-bundle: ^3.32
- sonata-project/doctrine-orm-admin-bundle: ^3.4.2
- symfony/validator: ^2.7|^3.0|^4.0
Requires (Dev)
- movingimage/style-checker: dev-master
- phpunit/phpunit: ^5.0 || ^6.0 || ^7.0 || ^8.0
This package is not auto-updated.
Last update: 2020-02-07 09:33:53 UTC
README
Symfony bundle that provides commenting functionality (posting, reading and administering comments).
Features include:
- API endpoint for fetching existing comments (supports pagination)
- API endpoint for posting comments
- Admin area for administering comments (listing, publishing and rejecting)
Installation
Add composer dependency:
composer require movingimage/mi-comments-bundle
Include MICommentsBundle and dependent Bundles in your AppKernel.php:
$bundles = [
//...
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), //optional
new MovingImage\Bundle\MICommentsBundle\MICommentsBundle(),
];
Include bundle routes to routing.yml:
mi_comments:
resource: "@MICommentsBundle/Resources/config/routing.yml"
prefix: /
You may choose a different prefix if required.
Configure the bundle in config.yml
mi_comments:
auto_publish: true //optional, by default is false
css: /path/to/css/file //optional
display_max_length: 100 //optional
Configure doctrine migrations bundle in config.yml (optional)
doctrine_migrations:
dir_name: "%kernel.root_dir%/../vendor/movingimage/mi-comments-bundle/Migrations"
namespace: MovingImage\Bundle\MICommentsBundle\Migrations
table_name: mi_comments_bundle_migration_versions
name: MICommentsBundle Migrations
organize_migrations: false
custom_template: ~
If you are already using doctrine migrations bundle in your project, keep your current configuration, but copy the migration files from Migrations directory to your existing migrations directory. Alternatively create the required table manually. In this case you don't need to use the doctrine migrations bundle.
Configure Sonata Admin Bundle (optional)
- Add SonataBundle and dependent bundles to AppKernel.php:
$bundles = [
//...
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
];
- Enable translator in config.yml
translator: { fallbacks: ['%locale%'] }
- Configure sonata bundle in config.yml
sonata_block:
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
sonata_admin: ~
- Configure routes in routing.yml
mi_comments_admin:
resource: "@MICommentsBundle/Resources/config/admin_routing.yml"
prefix: /admin
You may choose a different prefix if required.
- Install assets
./bin/console assets:install
Configuration parameters
Parameter | Type | Default | Required | Description |
---|---|---|---|---|
auto_publish | boolean | false | no | If true, comments are automatically published. |
css | string | null | no | Path to CSS file. If provided, will be included in the sonata layout. |
display_max_length | int | 20 | no | Maximum length of the comment displayed in the sonata list. |
Usage
POST a comment
curl -X POST \
http://<base_url>/comments \
-H 'Content-Type: application/json' \
-d '{
"user": {
"email": "pavle.predic@movingimage.com",
"name": "Pavle Predic"
},
"entity": {
"id": "DF3osABraqfGPaSGtty8vt",
"title": "Recruiting Teaser Karo & Matthias"
},
"comment": "What an awesome video! Great job!"
}'
GET published comments
curl -X GET <base_url>/comments?entityId=DF3osABraqfGPaSGtty8vt&limit=10&offset=20
This will return a list of published comments for the specified video ID (if provided), ordered by creation date (newest first). If no limit and offset are provided, the defaults will be used (limit: 10, offset: 0).
License
This bundle is under the BSD 3-clause license. Please check the LICENSE file for the complete license.