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 Generator Bundle Laravel Package

cedriclombardot/admingenerator-generator-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require cedriclombardot/admingenerator-generator-bundle
    

    Add to AppKernel.php:

    new CedricLombardot\AdminGeneratorBundle\AdminGeneratorBundle(),
    
  2. First Configuration Create a YAML config file (e.g., app/config/admin.yml):

    admin_generator:
        generation_parameters:
            namespace_admin: 'AppBundle\\Admin'
            namespace_entity: 'AppBundle\\Entity'
            namespace_form: 'AppBundle\\Form'
            namespace_repository: 'AppBundle\\Repository'
            namespace_controller: 'AppBundle\\Controller'
            namespace_twig: 'AppBundle\\Resources\\views'
    
  3. Generate a Basic CRUD Create a YAML file for your entity (e.g., app/config/admin/PostAdmin.yml):

    PostAdmin:
        entity: AppBundle\Entity\Post
        list:
            fields: [id, title, content, createdAt]
        form:
            fields: [title, content]
    

    Run the generator:

    php app/console admin:generate --entity=Post
    
  4. Access the Admin Panel Route to the generated controller (e.g., /admin/post).


First Use Case: Quick CRUD for a New Entity

  • Define a YAML config for your entity (e.g., UserAdmin.yml).
  • Run php app/console admin:generate --entity=User.
  • Customize the generated Twig templates in app/Resources/views/Admin/.
  • Access /admin/user to manage records.

Implementation Patterns

Workflow: Entity Management

  1. Define YAML Config Use admin.yml to configure:

    • List display fields (list.fields).
    • Form fields (form.fields).
    • Custom actions (actions).
    • Filters (filters).
  2. Generate and Customize

    php app/console admin:generate --entity=Product --force
    

    Override templates in app/Resources/views/Admin/Product/ to extend default behavior.

  3. Integrate with Existing Code

    • Extend generated controllers/forms:
      namespace AppBundle\Admin;
      use AppBundle\Admin\GeneratedProductAdmin as BaseProductAdmin;
      class ProductAdmin extends BaseProductAdmin {
          public function configure() {
              parent::configure();
              $this->menu->addLink('Custom Link', 'custom_route');
          }
      }
      
    • Use generated services in other bundles via dependency injection.

Integration Tips

  • Doctrine Integration Ensure your Entity classes are properly mapped (e.g., @ORM\Entity). Use repository_class in YAML to override the default repository.

  • Twig Customization Extend base templates (list.html.twig, edit.html.twig) by copying them to your bundle’s Resources/views/Admin/.

  • Routing Generate routes dynamically via YAML:

    routes:
        list: /admin/product/list
        edit: /admin/product/edit/{id}
    
  • Validation Add custom validation rules in YAML:

    form:
        fields:
            price:
                type: money
                constraints: [NotBlank, GreaterThan(0)]
    

Gotchas and Tips

Pitfalls

  1. YAML Syntax Errors

    • Validate YAML with yaml.lint or an online validator before running the generator.
    • Common issues: Missing colons, incorrect indentation (use spaces, not tabs).
  2. Namespace Conflicts

    • Ensure generation_parameters.namespace_* in admin.yml match your bundle structure.
    • Regenerate with --force if namespaces are misconfigured.
  3. Outdated Generator

    • The package is abandoned (last release: 2014). Use at your own risk.
    • Fork or migrate to alternatives like EasyAdmin or SonataAdmin.
  4. Twig Template Overrides

    • If templates aren’t updating, clear the cache:
      php app/console cache:clear
      

Debugging

  1. Generator Logs Run with -v for verbose output:

    php app/console admin:generate --entity=Post -v
    
  2. Doctrine Issues

    • Ensure your Entity has proper annotations/attributes (e.g., @ORM\Table).
    • Check for circular references or invalid property types.
  3. Route Conflicts

    • Use php app/console debug:router to verify routes.
    • Customize routes in YAML to avoid clashes.

Tips

  1. Partial Generates Use --partial to generate only specific parts (e.g., forms or controllers):

    php app/console admin:generate --entity=Post --partial=form
    
  2. Reuse Configs Extend base configs with extends in YAML:

    PostAdmin:
        extends: BaseAdmin
        entity: AppBundle\Entity\Post
    
  3. Custom Actions Add actions via YAML:

    actions:
        custom:
            label: 'Publish'
            icon: 'pencil'
            type: 'link'
            link: 'publish_post'
            role: 'ROLE_ADMIN'
    

    Implement the action in your extended admin class.

  4. Performance

    • Disable generation of unused files (e.g., skip tests or docs) via YAML flags.
    • Cache generated templates if regenerating frequently.
  5. Legacy Support

    • For Symfony 2.3+, pin the version in composer.json to avoid compatibility issues.
    • Test in a staging environment first due to potential breaking changes.
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