Installation:
composer require lag/adminbundle
Add to config/bundles.php:
return [
// ...
Lag\AdminBundle\LagAdminBundle::class => ['all' => true],
];
Basic Configuration:
Create a YAML config file (e.g., config/admin.yml) under config/packages/lag_admin/:
lag_admin:
resources:
App\Entity\User:
title: "Users"
list: ["id", "email", "roles"]
fields: ["id", "email", "roles"]
actions: ["show", "edit", "delete"]
First Use Case:
Generate a CRUD interface for an entity (e.g., User) by defining its configuration in YAML. Access the admin panel at /admin.
Entity Configuration:
@Admin annotation) for dynamic configurations:
use Lag\AdminBundle\Annotation\Admin;
/**
* @Admin(
* title="Posts",
* list={"id", "title", "createdAt"},
* fields={"title", "content", "published"}
* )
*/
class Post {}
Customizing Views:
LagAdminBundle::admin.html.twig or LagAdminBundle::crud.html.twig.templates/lag_admin/crud/edit.html.twig to modify the edit form.Field-Specific Logic:
text, boolean, association) in YAML:
fields:
title:
type: text
options:
label: "Post Title"
published:
type: boolean
options:
label: "Is Published"
Permissions & Security:
security.yml:
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
@Admin(accessControl="ROLE_SUPER_ADMIN") on entities for granular control.Integration with Forms:
FormType and referencing it in YAML:
form_type: App\Form\PostType
Bulk Actions:
actions:
bulk: ["delete", "export"]
API Endpoints:
JsonResponse in custom actions.YAML vs. Attributes:
Caching Issues:
php bin/console cache:clear) after changing YAML configs or annotations. The bundle caches configurations aggressively.Field Type Mismatches:
list, fields, and actions match the entity’s properties exactly (case-sensitive). Typos cause silent failures.Symfony 5+ Compatibility:
Translation Quirks:
translations/messages.fr.yml by default. Override in your project’s translation files.Database Changes:
Enable Debug Mode:
APP_DEBUG=true in .env to see detailed errors in the admin panel.Check Config Dumping:
php bin/console debug:config lag_admin to verify loaded configurations.Log Configuration:
config/packages/dev/lag_admin.yml to log parsed configs:
debug: true
Template Overrides:
templates/bundles/lagadmin/crud/edit.html.twig).Custom Field Types:
Lag\AdminBundle\Form\Type\AbstractFieldType and register it in the bundle’s services.Event Listeners:
prePersist, postRemove) via Symfony’s event dispatcher:
// config/services.yaml
Lag\AdminBundle\EventListener\YourListener:
tags:
- { name: kernel.event_listener, event: lag_admin.pre_save, method: onPreSave }
Dynamic Configuration:
Lag\AdminBundle\Manager\AdminManager service to fetch or modify configurations at runtime:
$config = $this->container->get('lag_admin.manager.admin')->getConfig('App\Entity\User');
Custom Actions:
actions:
custom: ["publish"]
Then implement the logic in a controller or via a form handler.Asset Management:
```markdown
---
How can I help you explore Laravel packages today?