Installation:
composer require sonata-project/core-bundle
Add to config/bundles.php:
return [
// ...
Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
];
First Use Case:
sonata_admin bundle (which depends on this core bundle).SonataCoreBundle's routing configuration in config/routes/sonata_admin.yaml:
sonata_admin:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
Where to Look First:
config/packages/sonata_core.yaml (auto-generated if missing).vendor/sonata-project/core-bundle/Resources/views/.Admin Integration:
sonata.admin service to access admin services:
$adminPool = $this->get('sonata.admin.pool');
$admin = $adminPool->getAdminByAdminCode('YourAdminClass');
configureFormFields() or configureListFields() in your custom admin classes.Asset Management:
sonata.block.service.block_pool for dynamic blocks. Register a block service:
# config/services.yaml
services:
App\Block\MyBlockService:
tags:
- { name: sonata.block }
Security:
sonata.security.impersonating_proxy for user impersonation (if enabled). Configure in config/packages/security.yaml:
security:
impersonating: ~
Event Listeners:
sonata.admin.event.configure):
use Sonata\AdminBundle\Event\ConfigureEvent;
public function onAdminConfigure(ConfigureEvent $event) {
$event->getAdmin()->getShow()->setActions(['list', 'create']);
}
Tag your listener:
tags:
- { name: kernel.event_listener, event: sonata.admin.event.configure, method: onAdminConfigure }
Translation:
translations/messages.en.yaml:
sonata_admin:
block:
title: "Custom Block Title"
symfony/console and symfony/dependency-injection via spatie/laravel-symfony-support for Sonata integration.config/packages/doctrine.yaml if using Laravel’s Eloquent.sonata_block):
{{ render(block('block_name')) }}
Deprecation Warning:
Symfony-Specific:
Routing Conflicts:
/admin) may clash with Laravel’s routes. Use route prefixes or middleware to isolate:
// routes/web.php
Route::prefix('admin')->middleware(['web', 'auth'])->group(function () {
// Sonata routes here
});
Doctrine Events:
prePersist). Override these carefully to avoid conflicts with Laravel’s Eloquent events.Asset Pipeline:
webpack.mix.js to handle Sonata’s JS/CSS:
mix.copy('vendor/sonata-project/core-bundle/web/bundles/sonataadmin/less', 'public/assets/sonata');
Enable Debug Mode:
SONATA_DEBUG env var or add to config/packages/sonata_core.yaml:
sonata_core:
debug: true
Log Events:
sonata_core:
logging:
enabled: true
level: debug
Common Errors:
config/bundles.php and dependencies (e.g., sonata-doctrine-orm-admin) are installed.php bin/console cache:clear) and verify template paths in templates/ or vendor/.Database Migrations:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Custom Blocks:
Sonata\BlockBundle\Block\BlockContextAwareInterface to create reusable blocks. Example:
class CustomBlock extends BlockBase {
public function execute(BlockContextInterface $blockContext, Response $response) {
return $response->setContent('Custom content');
}
}
Admin Customization:
vendor/sonata-project/core-bundle/Resources/views/ to templates/SonataAdminBundle/.class CustomPostAdmin extends SonataAdminBundleAdmin {
protected function configureFormFields(FormMapper $formMapper) {
$formMapper->add('title', 'text');
}
}
Security Roles:
security.yaml:
roles:
SonataAdminBundle:
resource: '@SonataAdminBundle/Resources/config/security/roles.yml'
Internationalization:
$translator->trans('sonata_admin.block.title', [], 'SonataCoreBundle');
Performance:
sonata_core.debug) in production.sonata.core.cache to optimize rendering:
sonata_core:
cache:
app: cache.app
security: cache.security
How can I help you explore Laravel packages today?