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

Cruditplatform Bundle Laravel Package

2lenet/cruditplatform-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require 2lenet/cruditplatform-bundle
    

    Then enable the bundle in config/bundles.php:

    return [
        // ...
        TwoLenet\CruditPlatformBundle\TwoLenetCruditPlatformBundle::class => ['all' => true],
    ];
    
  2. Publish Configuration:

    php bin/console cruditplatform:install
    

    This generates default config files in config/packages/two_lenet_crudit_platform.yaml.

  3. First Use Case: Create a CRUD controller scaffold for an existing entity (e.g., Post):

    php bin/console make:crudit Post
    

    This generates a controller, routes, and basic CRUD logic in src/Controller/PostCruditController.php.


Where to Look First

  • Bundle Docs: Check vendor/two_lenet/cruditplatform-bundle/README.md for CLI commands and conventions.
  • Generated Files: After running make:crudit, inspect:
    • src/Controller/{Entity}CruditController.php (core logic).
    • config/routes/crudit.yaml (auto-generated routes).
  • Configuration: Override defaults in config/packages/two_lenet_crudit_platform.yaml (e.g., form fields, permissions).

Implementation Patterns

Core Workflow

  1. Entity-Based CRUD: Use make:crudit to scaffold controllers for entities. The bundle auto-detects Doctrine entities and generates:

    • Index/list actions (index()).
    • Create/read/update/delete actions (new(), create(), edit(), update(), delete()).
    • Form types (via Symfony’s FormBuilder).
  2. Customization: Extend the base controller (src/Controller/BaseCruditController.php) to add business logic:

    namespace App\Controller;
    
    use TwoLenet\CruditPlatformBundle\Controller\BaseCruditController;
    
    class PostCruditController extends BaseCruditController
    {
        protected function configureFormFields(): array
        {
            return [
                'title' => 'text',
                'content' => 'textarea',
                // Override or add fields
            ];
        }
    }
    
  3. Routing: Routes are auto-generated in config/routes/crudit.yaml. Customize by extending the bundle’s router:

    two_lenet_crudit_platform:
        resource: '!@TwoLenetCruditPlatformBundle/Resources/config/routing.yaml'
        prefix: '/admin'  # Override base path
    
  4. Permissions: Use the access_control config to restrict actions:

    two_lenet_crudit_platform:
        access_control:
            PostCruditController:
                index: ROLE_ADMIN
                create: ROLE_EDITOR
    

Integration Tips

  • Doctrine Events: Hook into lifecycle events (e.g., prePersist) in your extended controller:

     protected function prePersist($entity): void
     {
         $entity->setCreatedAt(new \DateTime());
     }
    
  • Form Extensions: Extend the bundle’s form types (e.g., TwoLenet\CruditPlatformBundle\Form\Type\CruditFormType) to add custom fields or validation:

     namespace App\Form\Type;
    
     use Symfony\Component\Form\AbstractType;
     use TwoLenet\CruditPlatformBundle\Form\Type\CruditFormType;
    
     class ExtendedCruditFormType extends CruditFormType
     {
         public function buildForm(FormBuilderInterface $builder, array $options)
         {
             $builder->add('custom_field', TextType::class);
         }
     }
    

    Then reference it in configureFormFields().

  • Twig Templates: Override templates in templates/two_lenet_crudit_platform/ to customize UI (e.g., _form.html.twig).

  • API Support: The bundle includes JSON responses by default. Extend BaseCruditController to add API-specific logic:

     public function indexApi(Request $request): JsonResponse
     {
         $data = $this->indexAction($request);
         return $this->json($data);
     }
    

Gotchas and Tips

Pitfalls

  1. Entity Naming: The make:crudit command expects Doctrine entities with setters/getters for fields. Avoid magic properties or __get()/__set() unless explicitly supported.

  2. Configuration Overrides: Changes to config/packages/two_lenet_crudit_platform.yaml require a cache clear:

    php bin/console cache:clear
    
  3. Form Field Mismatches: If a field in your entity isn’t reflected in the form, ensure:

    • The field is listed in configureFormFields().
    • The field type (e.g., 'text', 'date') matches the entity property type.
  4. Route Conflicts: The bundle auto-generates routes. Avoid naming conflicts by:

    • Using unique controller names (e.g., PostCruditController vs. posts).
    • Customizing the prefix in crudit.yaml.
  5. Debugging: Enable debug mode in config/packages/dev/two_lenet_crudit_platform.yaml:

    debug: true
    

    This logs SQL queries and form data.


Debugging Tips

  • Check Generated SQL: Use Doctrine’s query logging:

    php bin/console debug:config doctrine
    

    Set SQL logging to true.

  • Form Debugging: Dump form data in your controller:

    public function create(Request $request)
    {
        $form = $this->createForm();
        $form->handleRequest($request);
    
        if ($form->isSubmitted() && $form->isValid()) {
            dump($form->getData()); // Debug submitted data
        }
    }
    
  • Event Listeners: Add a listener to debug entity events:

    namespace App\EventListener;
    
    use Doctrine\Common\EventSubscriber;
    use Doctrine\ORM\Event\LifecycleEventArgs;
    
    class CruditDebugSubscriber implements EventSubscriber
    {
        public function getSubscribedEvents(): array
        {
            return ['prePersist', 'preUpdate'];
        }
    
        public function prePersist(LifecycleEventArgs $args): void
        {
            dump($args->getObject());
        }
    }
    

    Register it in services.yaml:

    services:
        App\EventListener\CruditDebugSubscriber:
            tags: ['doctrine.event_subscriber']
    

Extension Points

  1. Custom Actions: Add actions to the controller by extending BaseCruditController:

    public function publish(Request $request, $id)
    {
        $entity = $this->getEntityManager()->find($this->entityClass, $id);
        $entity->setStatus('published');
        $this->getEntityManager()->flush();
        return $this->redirectToIndex();
    }
    

    Add the route in config/routes/crudit.yaml:

    publish:
        path: /{id}/publish
        methods: [POST]
        defaults: { _controller: 'App\Controller\PostCruditController::publish' }
    
  2. Dynamic Field Mapping: Override configureFormFields() to dynamically map fields based on entity metadata:

    protected function configureFormFields(): array
    {
        $fields = [];
        foreach ($this->getEntityManager()->getClassMetadata($this->entityClass)->getFieldNames() as $field) {
            $fields[$field] = match ($field) {
                'published_at' => 'datetime',
                default => 'text',
            };
        }
        return $fields;
    }
    
  3. Bulk Actions: Extend the index action to support bulk operations:

    public function index(Request $request)
    {
        $entities = $this->getEntities();
        $form = $this->createBulkForm($entities)->handleRequest($request);
    
        if ($form->isSubmitted() && $form->isValid()) {
            $this->bulkAction($form->getData());
        }
    
        return $this->renderIndex($entities);
    }
    
  4. Soft Deletes: Integrate with gedmo/doctrine-extensions for soft deletes:

    two_lenet_crudit_platform:
        soft_delete: true
    

    Then extend the delete() action to use soft delete logic.


Configuration Quirks

  • Default Values: The bundle assumes id as the primary key. For UUIDs or custom IDs, override the idField in config:

    two_lenet_crudit_platform:
        entities:
            Post:
                id_field: uuid
    
  • Translation: Form labels/placeholders use Symfony’s translation system. Ensure your translations are loaded:

    # config/packages/translation.yaml
    
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