draw/sonata-integration-bundle
Installation:
composer require draw/sonata-integration-bundle
Add to config/bundles.php:
return [
// ...
Draw\SonataIntegrationBundle\DrawSonataIntegrationBundle::class => ['all' => true],
];
Configuration:
Enable the bundle in config/packages/draw_sonata_integration.yaml:
draw_sonata_integration:
console:
admin: true # Enable admin UI
commands:
clearCache:
commandName: "cache:clear"
label: "Clear Cache"
icon: "fa-trash"
First Use Case:
/admin/integrations to see the new Integrations tab in Sonata Admin.clearCache) to trigger the underlying Symfony console command via the UI.Command Integration:
config/packages/draw_sonata_integration.yaml under commands.fos:elastica:populate).cache, search).Admin UI Customization:
templates/DrawSonataIntegrationBundle/admin/integrations/index.html.twig) to modify the UI.Draw\SonataIntegrationBundle\Admin\IntegrationAdmin class for custom logic.Dynamic Command Loading:
draw_sonata_integration.command_loader service to dynamically load commands from other bundles or services:
services:
App\Command\CustomCommandLoader:
tags: ['draw_sonata_integration.command_loader']
Permissions:
draw_sonata_integration:
console:
commands:
reIndexSearch:
roles: [ROLE_SUPER_ADMIN]
$command = $this->get('command');
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$command->run($output, ['command' => 'cache:clear']);
fos:elastica:populate), use Symfony Messenger or a queue system to avoid UI timeouts.Command Not Found:
commandName in YAML matches exactly the Symfony console command (including namespace if required).php bin/console list to verify command names.Permission Denied:
security.yaml:
access_control:
- { path: ^/admin/integrations, roles: ROLE_USER }
Template Overrides:
php bin/console cache:clear) to see changes.Bundle Maturity:
draw_sonata_integration:
console:
commands:
reIndexSearch:
commandName: "fos:elastica:populate"
logOutput: true # (Hypothetical feature; log manually if needed)
php bin/console debug:container draw_sonata_integration.command_loader
Custom Command Loaders:
Implement Draw\SonataIntegrationBundle\Loader\CommandLoaderInterface to fetch commands from APIs or databases.
Dynamic Icons:
Use Font Awesome or custom icons by extending the IntegrationAdmin class:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('icon', 'sonata_type_model_list', [
'model_manager' => $this->modelManager,
'source_key' => 'icon',
'by_reference' => false,
]);
}
Event Listeners:
Hook into Sonata’s events (e.g., sonata.admin.event.CRUD) to dynamically enable/disable commands:
$event->getSubject()->addToCollection($command);
How can I help you explore Laravel packages today?