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

Adminbundle Laravel Package

bluebear/adminbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require lag/adminbundle
    

    Add to config/bundles.php:

    return [
        // ...
        Lag\AdminBundle\LagAdminBundle::class => ['all' => true],
    ];
    
  2. 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"]
    
  3. 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.


Implementation Patterns

Common Workflows

  1. Entity Configuration:

    • Use YAML for simple setups or PHP attributes (via @Admin annotation) for dynamic configurations:
      use Lag\AdminBundle\Annotation\Admin;
      
      /**
       * @Admin(
       *     title="Posts",
       *     list={"id", "title", "createdAt"},
       *     fields={"title", "content", "published"}
       * )
       */
      class Post {}
      
  2. Customizing Views:

    • Override default templates by extending LagAdminBundle::admin.html.twig or LagAdminBundle::crud.html.twig.
    • Example: Create templates/lag_admin/crud/edit.html.twig to modify the edit form.
  3. Field-Specific Logic:

    • Use field types (e.g., text, boolean, association) in YAML:
      fields:
          title:
              type: text
              options:
                  label: "Post Title"
          published:
              type: boolean
              options:
                  label: "Is Published"
      
  4. Permissions & Security:

    • Restrict access via security.yml:
      access_control:
          - { path: ^/admin, roles: ROLE_ADMIN }
      
    • Use @Admin(accessControl="ROLE_SUPER_ADMIN") on entities for granular control.
  5. Integration with Forms:

    • Extend entity forms by creating a FormType and referencing it in YAML:
      form_type: App\Form\PostType
      
  6. Bulk Actions:

    • Enable bulk actions (e.g., delete, export) in YAML:
      actions:
          bulk: ["delete", "export"]
      
  7. API Endpoints:

    • Expose admin data via API by extending the bundle’s controllers or using Symfony’s JsonResponse in custom actions.

Gotchas and Tips

Pitfalls

  1. YAML vs. Attributes:

    • YAML is parsed after annotations, so attribute-based configs override YAML. Use one or the other per entity to avoid conflicts.
  2. Caching Issues:

    • Clear the cache (php bin/console cache:clear) after changing YAML configs or annotations. The bundle caches configurations aggressively.
  3. Field Type Mismatches:

    • Ensure field names in list, fields, and actions match the entity’s properties exactly (case-sensitive). Typos cause silent failures.
  4. Symfony 5+ Compatibility:

    • The bundle was last updated in 2020 and may require patches for Symfony 5.3+/6.x. Check for forks or community fixes (e.g., this issue).
  5. Translation Quirks:

    • Translations for labels/buttons (e.g., "Delete") are loaded from translations/messages.fr.yml by default. Override in your project’s translation files.
  6. Database Changes:

    • The bundle does not handle migrations. Use Doctrine Migrations or similar tools for schema updates.

Debugging Tips

  1. Enable Debug Mode:

    • Set APP_DEBUG=true in .env to see detailed errors in the admin panel.
  2. Check Config Dumping:

    • Run php bin/console debug:config lag_admin to verify loaded configurations.
  3. Log Configuration:

    • Add this to config/packages/dev/lag_admin.yml to log parsed configs:
      debug: true
      
  4. Template Overrides:

    • If overrides aren’t working, ensure your template paths follow Symfony’s template hierarchy (e.g., templates/bundles/lagadmin/crud/edit.html.twig).

Extension Points

  1. Custom Field Types:

    • Create a new field type by extending Lag\AdminBundle\Form\Type\AbstractFieldType and register it in the bundle’s services.
  2. Event Listeners:

    • Hook into lifecycle events (e.g., 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 }
      
  3. Dynamic Configuration:

    • Use the Lag\AdminBundle\Manager\AdminManager service to fetch or modify configurations at runtime:
      $config = $this->container->get('lag_admin.manager.admin')->getConfig('App\Entity\User');
      
  4. Custom Actions:

    • Add custom actions (e.g., "publish") by extending the bundle’s action system:
      actions:
          custom: ["publish"]
      
      Then implement the logic in a controller or via a form handler.
  5. Asset Management:

    • Override CSS/JS by extending the bundle’s asset pipeline or using Symfony’s asset component to prepend/append files.

```markdown
---
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log