elao / html-action-bundle
A set of HTML actions for elao/admin-bundle.
Installs: 192
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 19
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- elao/admin-bundle: ^1.1
- symfony/framework-bundle: ~3.1
README
This bundle provides CRUD + List Actions to be used with ElaoAdminBundle
Installation
Require the bundle in Composer:
$ composer require elao/html-action-bundle
Install the bundle in your AppKernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( //... // ElaoHtmlActionBundle requires ElaoAdminBundle, you'll need to register it too. // new Elao\Bundle\ElaoAdminBundle\ElaoAdminBundle(), new Elao\Bundle\HtmlActionBundle\ElaoHtmlActionBundle(), ); }
##Configuration
The HtmlActionBundle provides 5 actions for the AdminBundle:
- html_list: a list of models. e.g. "GET /posts"
- html_create: a creation form and its POST handler. e.g. "GET|POST /posts/new"
- html_read: details for a single model. e.g. "GET /posts/{id}"
- html_update: a modification form for a single model and its POST handler. e.g. "GET|POST /posts/{id}/edit"
- html_delete: a deletion form for a single model (ask for user confirmation) and its POST handler. e.g. "GET|DELETE /posts/{id}/delete"
Here's how you define a simple CRUD administration for a "Post" entity.
elao_admin: administrations: # Administration, named after the model, will impact urls and route names post: # The repository service for the Post model (usually DoctrineRepository for model "Post") repository: blog.repository.post # The list of actions actions: list: # We're using default values for the list html_list: ~ create: html_create: # Specify the form type to use to create a Post form: BlogBundle\Form\PostType update: html_update: # Specify the form type to use to edit a Post form: BlogBundle\Form\PostType read: # We're using default values for the read html_read: ~ delete: html_delete: # We're adding a security restriction on the delete action security: has_role('ROLE_ADMIN')
Don't forget to declare the corresponding repository service:
(extends elao_admin.repository.doctrine
/Elao\Bundle\AdminBundle\Service\DoctrineRepository
or use your own implementation of Elao\Bundle\AdminBundle\Behaviour\RepositoryInterface
)
# services.yml blog.repository.post: parent: elao_admin.repository.doctrine arguments: ['BlogBundle\Entity\Post']
Full configuration
List
Create
Read
Update
Delete
Views
Please note that the views are not provided with the bundle. You have to create them to display the different forms.
Default path for the views is app/Resources/[name]/[alias].html.twig
.
You can override this by setting an explicit view in action's options.
Doctrine service repositories (optional):
For convenience, you can use AdminBundle's DoctrineRepository as the default doctrine repository.
This way the Doctrine entity manager's getRepository
method will return the repository service declared for each model.
To activate this feature:
# config.yml
elao_admin:
doctrine_service_repositories: true
doctrine:
default_repository_class: Elao\Bundle\AdminBundle\Service\DoctrineRepository
repository_factory: elao_admin.repository_factory.doctrine