Weave Code
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

Admingenerator User Bundle Laravel Package

cedriclombardot/admingenerator-user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Dependencies

    composer require cedriclombardot/admingenerator-user-bundle
    composer require symfony2admingenerator/generator-bundle
    composer require friendsofsymfony/user-bundle
    
  2. Enable Bundles in config/bundles.php:

    return [
        // ...
        CedricLombardot\AdmingeneratorUserBundle\CedricLombardotAdmingeneratorUserBundle::class => ['all' => true],
        Symfony2\AdmingeneratorBundle\GeneratorBundle::class => ['all' => true],
        FOS\UserBundle\FOSUserBundle::class => ['all' => true],
    ];
    
  3. Configure FOSUserBundle (if not already done):

    # config/packages/fos_user.yaml
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: App\Entity\User
    
  4. Generate a User Admin via CLI:

    php bin/console generate:admin --entity=App\Entity\User --generator=admingenerator --force
    
  5. Configure Base Layout in config/packages/cedric_lombardot_admingenerator_user.yaml:

    cedric_lombardot_admingenerator_user:
        base_layout: 'admin_base.html.twig'
        assets:
            css: ['bundles/admingenerator/css/admin.css']
            js: ['bundles/admingenerator/js/admin.js']
    
  6. Create a Base Layout at templates/admin/base.html.twig:

    {% extends 'fos_user_security/login.html.twig' %}
    {% block body %}
        {% block admin_content %}{% endblock %}
    {% endblock %}
    

First Use Case

Generate a CRUD interface for User entity with FOSUserBundle integration:

php bin/console generate:admin --entity=App\Entity\User --generator=admingenerator --force

This auto-generates a user management panel with FOSUserBundle fields (e.g., username, email, roles).


Implementation Patterns

Workflow Integration

  1. FOSUserBundle + AdminGenerator Sync

    • Extend User entity with custom fields (e.g., phone, address) and regenerate the admin:
      php bin/console generate:admin --entity=App\Entity\User --generator=admingenerator --force
      
    • The bundle auto-maps FOSUserBundle fields (e.g., plainPassword, enabled) to the admin form.
  2. Custom Field Handling

    • Override field types in config/packages/admingenerator.yaml:
      admingenerator:
          generation_parameters:
              App\Entity\User:
                  fields:
                      plainPassword: { type: password }
                      roles: { type: entity, class: App\Entity\Role }
      
  3. Twig Template Overrides

    • Customize the admin layout by extending admin_base.html.twig:
      {% extends 'admin_base.html.twig' %}
      {% block admin_content %}
          {{ include('admingenerator_user::user/edit.html.twig') }}
      {% endblock %}
      
  4. Action Hooks

    • Add pre/post actions in config/packages/admingenerator.yaml:
      admingenerator:
          generation_parameters:
              App\Entity\User:
                  actions:
                      prePersist: ['App\EventListener\UserPrePersistListener']
                      postRemove: ['App\EventListener\UserPostRemoveListener']
      
  5. Authentication Integration

    • Secure the admin panel with FOSUserBundle’s firewall:
      # config/packages/security.yaml
      firewalls:
          admin:
              pattern: ^/admin
              form_login:
                  provider: fos_userbundle
                  check_path: /login_check
                  login_path: /login
      

Common Patterns

  • Bulk Actions: Enable via config:
    admingenerator:
        generation_parameters:
            App\Entity\User:
                bulk_actions: ['delete', 'enable', 'disable']
    
  • Field Groups: Organize fields in tabs:
    fields:
        group_account:
            fields: [username, email, enabled]
        group_security:
            fields: [roles, plainPassword]
    
  • Validation: Leverage FOSUserBundle validators (e.g., UniqueEntity) in your User entity.

Gotchas and Tips

Pitfalls

  1. Deprecated Bundle

    • Last release in 2014; may conflict with modern Symfony (5.4+/Laravel-like ecosystems).
    • Mitigation: Fork the repo and update dependencies (e.g., symfony/form, twig) manually.
  2. YAML Configuration Overrides

    • Config in admingenerator.yaml overwrites defaults but may break if malformed.
    • Tip: Use php bin/console debug:config admingenerator to validate.
  3. FOSUserBundle Mismatch

    • Bundle assumes FOSUserBundle’s default entity structure (User with username, email).
    • Fix: Extend User entity and regenerate:
      php bin/console make:entity --regenerate App\Entity\User
      
  4. Asset Paths

    • Hardcoded asset paths (e.g., bundles/admingenerator/) may fail in custom setups.
    • Workaround: Override asset paths in base_layout config or use Symfony’s asset component.
  5. Twig Template Caching

    • Generated templates may not update after config changes.
    • Solution: Clear cache:
      php bin/console cache:clear
      

Debugging Tips

  • Check Generated Code: Inspect app/config/generated/admingenerator/ for auto-generated files.
  • Enable Debug Mode: Add to config/packages/dev/debug.yaml:
    framework:
        router:
            debug: true
    
  • Log Configuration: Dump config to debug:
    php bin/console debug:config cedric_lombardot_admingenerator_user
    

Extension Points

  1. Custom Generators

    • Extend CedricLombardot\AdmingeneratorUserBundle\Generator\Generator to add logic (e.g., auto-assign roles).
  2. Event Listeners

    • Subscribe to admingenerator.generate events to modify generation dynamically:
      // src/EventListener/AdminGeneratorListener.php
      public function onGenerate(GenerateEvent $event) {
          $event->setParameter('custom_field', 'value');
      }
      
  3. Database Migrations

    • Use make:migration after extending User entity:
      php bin/console make:migration
      php bin/console doctrine:migrations:migrate
      
  4. Laravel Adaptation (Hypothetical)

    • Not natively supported, but could be adapted via:
      • Symfony Bridge (e.g., spatie/laravel-symfony-support).
      • Rewriting YAML configs as Laravel service providers.
      • Using Twig for templating via laravel-twig-bridge.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware