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

Generator Bundle Laravel Package

aleste/generator-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require aleste/generator-bundle
    

    Ensure SensioGeneratorBundle (~2.3) is installed (this bundle extends it).

  2. Enable the Bundle Add to config/bundles.php:

    Aleste\GeneratorBundle\AlesteGeneratorBundle::class => ['all' => true],
    
  3. First Use Case: Generate a CRUD with Pagination Run the generator command with pagination flags:

    php bin/console generate:doctrine:crud --entity=App\Entity\Post --paginate --paginator=knp_paginator
    
    • --paginate enables pagination.
    • --paginator=knp_paginator specifies the paginator bundle (default: knp_paginator or whiteoctober/paginator).
  4. Key Files to Review

    • src/Generator/Doctrine/Generator/EntityGenerator.php (core logic).
    • src/Resources/config/services.xml (service overrides).
    • src/Generator/Doctrine/Generator/FilterGenerator.php (filter templates).

Implementation Patterns

Workflow: Extending CRUD with Filters

  1. Generate a Filtered CRUD

    php bin/console generate:doctrine:crud --entity=App\Entity\User --filter --filter-fields=name,email,role
    
    • --filter adds a filter form to the list action.
    • --filter-fields specifies which fields to include in the filter.
  2. Customizing Filter Templates Override the default filter template by copying:

    vendor/aleste/generator-bundle/src/Resources/views/Filter/filter.html.twig
    

    to:

    templates/AlesteGeneratorBundle/Filter/filter.html.twig
    
  3. Integration with KNP Paginator Ensure knp/paginator-bundle is installed and configured. The bundle auto-detects it for pagination.

  4. Dynamic Field Selection Use --fields to control which fields appear in the list/view/edit forms:

    php bin/console generate:doctrine:crud --entity=App\Entity\Product --fields=id,name,price,stock
    
  5. Bootstrap Integration The bundle includes Bootstrap 3/4/5 support by default. Customize via:

    # config/packages/aleste_generator.yaml
    aleste_generator:
        bootstrap_version: 5  # Options: 3, 4, 5
    

Gotchas and Tips

Pitfalls

  1. Paginator Bundle Dependency

    • The bundle assumes knp/paginator-bundle or whiteoctober/paginator-bundle is installed. If missing, pagination fails silently.
    • Fix: Install the required bundle or set --paginator=null to disable pagination.
  2. Filter Field Validation

    • Filter fields must exist in the entity or the generator will throw an error.
    • Tip: Use --filter-fields=* to auto-detect all non-association fields.
  3. Template Overrides

    • Overriding templates requires the exact directory structure (AlesteGeneratorBundle/Filter/). A misplaced template will break rendering.
    • Debug Tip: Clear cache (php bin/console cache:clear) after template changes.
  4. Doctrine Lifecycle Conflicts

    • If the entity has custom lifecycle callbacks (e.g., prePersist), the generator may not handle them correctly in the CRUD forms.
    • Workaround: Manually edit the generated templates or extend the generator class.
  5. Bootstrap Version Mismatch

    • The bundle’s default CSS assumes Bootstrap 5. If using Bootstrap 4/3, ensure the bootstrap_version config matches your project’s assets.

Debugging Tips

  • Enable Debug Mode

    php bin/console debug:config aleste_generator
    

    to verify configuration.

  • Check Generated Files The bundle outputs files to src/Controller/, templates/, and config/routes/. Inspect these for errors.

  • Log Generator Output Add --verbose to commands to see detailed generation steps:

    php bin/console generate:doctrine:crud --entity=App\Entity\Post --verbose
    

Extension Points

  1. Custom Generators Extend Aleste\GeneratorBundle\Generator\Doctrine\Generator\EntityGenerator to add custom logic (e.g., API endpoints):

    namespace App\Generator\Doctrine\Generator;
    use Aleste\GeneratorBundle\Generator\Doctrine\Generator\EntityGenerator as BaseGenerator;
    
    class CustomEntityGenerator extends BaseGenerator {
        protected function configure() {
            $this->addOption('api', null, 'Generate API endpoints');
        }
    }
    

    Register the service in config/services.yaml:

    services:
        App\Generator\Doctrine\Generator\CustomEntityGenerator:
            tags: ['generator']
    
  2. Dynamic Field Mapping Override getFields() in a custom generator to dynamically include/exclude fields based on logic (e.g., ACL rules).

  3. Event Listeners Use Symfony events to modify generation behavior. Example:

    // src/EventListener/GeneratorListener.php
    use Aleste\GeneratorBundle\Event\GenerateEvent;
    
    class GeneratorListener {
        public function onGenerate(GenerateEvent $event) {
            $event->setTemplate('custom_template.html.twig');
        }
    }
    

    Bind the listener in config/services.yaml:

    services:
        App\EventListener\GeneratorListener:
            tags:
                - { name: kernel.event_listener, event: aleste.generator.generate, method: onGenerate }
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui