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

Sonata Core Bundle Laravel Package

awaresoft/sonata-core-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Symlink the Bundle Ensure the bundle is symlinked to /src/Awaresoft in your Laravel project (via utils/prepare_vendors or manual symlinking). Remove any Composer-installed version and update autoload_psr4.php to reflect the local path.

  2. Register the Bundle In config/app.php, add the bundle to the extra.bundles array:

    Awaresoft\SonataCoreBundle\SonataCoreBundle::class,
    
  3. Clear Cache Run:

    php artisan cache:clear
    php artisan config:clear
    
  4. First Use Case: Basic Admin Interface Extend the bundle’s admin generator to create a CRUD interface for a model:

    php artisan sonata:admin:generate --model=User --bundle=AcmeDemoBundle
    

    Then register the admin in services.yml (Symfony config) or via Laravel’s service provider.


Implementation Patterns

Workflow: Extending Admin Functionality

  1. Custom Admin Classes Override default admin behavior by extending SonataAdminService:

    namespace Acme\DemoBundle\Admin;
    
    use Awaresoft\SonataCoreBundle\Admin\AdminService;
    
    class UserAdmin extends AdminService
    {
        protected function configureListFields(ListMapper $listMapper)
        {
            $listMapper
                ->add('id')
                ->add('email')
                ->add('roles');
        }
    }
    
  2. Dynamic Route Configuration Use the bundle’s router to define admin routes in routing.yml:

    acme_demo_admin:
        resource: '@AcmeDemoBundle/Resources/config/routing/sonata_admin.xml'
        prefix: /admin
    
  3. Form Customization Extend forms via configureFormFields:

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name', 'text')
            ->add('isActive', 'checkbox', [
                'required' => false,
            ]);
    }
    
  4. Integration with Laravel Services Inject Laravel services (e.g., repositories) into admin classes via constructor:

    public function __construct(UserRepository $userRepo)
    {
        $this->userRepo = $userRepo;
        parent::__construct($id, $class, $baseControllerName);
    }
    
  5. Event Listeners Hook into lifecycle events (e.g., prePersist, postRemove) in your admin class:

    public function prePersist($object)
    {
        $object->setCreatedAt(now());
    }
    

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel Compatibility

    • The bundle is Symfony-centric. Use Laravel’s bridge (e.g., symfony/console) for CLI tools.
    • Avoid mixing Symfony’s EventDispatcher with Laravel’s events directly; wrap or proxy calls.
  2. Cache Invalidation After modifying admin classes or templates, clear both Laravel and Symfony caches:

    php artisan cache:clear
    php artisan config:clear
    php app/console cache:clear --env=prod
    
  3. Route Conflicts Ensure admin routes (/admin/*) don’t clash with Laravel’s default routes. Use route prefixes or middleware to isolate them.

  4. Template Overrides Override Sonata templates in resources/views/bundles/sonataadmin/ (Laravel) or templates/ (Symfony). Prioritize:

    /templates/AwaresoftSonataCoreBundle:Default:base_layout.html.twig
    
  5. Database Schema Migrations The bundle doesn’t handle migrations. Use Laravel’s migrate or Symfony’s doctrine:migrations separately.

Debugging Tips

  • Enable Symfony Debug Toolbar (if using Symfony components) to inspect requests, services, and events.
  • Log Admin Events: Extend SonataAdminService to log actions:
    public function postPersist($object)
    {
        \Log::info("Created {$object->getClass()} with ID {$object->getId()}");
    }
    
  • Check Route Generation: Dump routes to verify admin paths:
    php artisan route:list | grep admin
    

Extension Points

  1. Custom Controllers Override the base controller (SonataAdminController) for custom logic:

    namespace Acme\DemoBundle\Controller;
    
    use Awaresoft\SonataCoreBundle\Controller\SonataAdminController;
    
    class CustomAdminController extends SonataAdminController
    {
        public function customAction()
        {
            return $this->render('AcmeDemoBundle:Admin:custom.html.twig');
        }
    }
    
  2. Dynamic Permissions Use the bundle’s security system to restrict access:

    # config/security.yml
    access_control:
        - { path: ^/admin/, role: ROLE_ADMIN }
    
  3. API Integration Expose admin data via API by extending controllers or using Laravel’s apiResource alongside Sonata routes.

  4. Localization Override translation files in translations/AwaresoftSonataCoreBundle.en.yml (Symfony) or resources/lang/ (Laravel).

  5. Testing Use Symfony’s WebTestCase or Laravel’s HttpTests to test admin routes:

    public function testAdminList()
    {
        $client = static::createClient();
        $client->request('GET', '/admin/user');
        $this->assertResponseStatusCodeSuccess($client);
    }
    
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