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 Integration Bundle Laravel Package

draw/sonata-integration-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require draw/sonata-integration-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        Draw\SonataIntegrationBundle\DrawSonataIntegrationBundle::class => ['all' => true],
    ];
    
  2. 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"
    
  3. First Use Case:

    • Access /admin/integrations to see the new Integrations tab in Sonata Admin.
    • Click a command (e.g., clearCache) to trigger the underlying Symfony console command via the UI.

Implementation Patterns

Workflows

  1. Command Integration:

    • Define commands in config/packages/draw_sonata_integration.yaml under commands.
    • Use Symfony’s console command names (e.g., fos:elastica:populate).
    • Group related commands under logical categories (e.g., cache, search).
  2. Admin UI Customization:

    • Override the admin template (templates/DrawSonataIntegrationBundle/admin/integrations/index.html.twig) to modify the UI.
    • Extend the Draw\SonataIntegrationBundle\Admin\IntegrationAdmin class for custom logic.
  3. Dynamic Command Loading:

    • Use the 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']
      
  4. Permissions:

    • Restrict access to commands via Sonata’s security system:
      draw_sonata_integration:
          console:
              commands:
                  reIndexSearch:
                      roles: [ROLE_SUPER_ADMIN]
      

Integration Tips

  • Leverage Existing Sonata Features: Use Sonata’s built-in ACLs or custom permissions to control command visibility.
  • Logging: Wrap command execution in a service to log outputs or errors:
    $command = $this->get('command');
    $output = new \Symfony\Component\Console\Output\BufferedOutput();
    $command->run($output, ['command' => 'cache:clear']);
    
  • Async Execution: For long-running commands (e.g., fos:elastica:populate), use Symfony Messenger or a queue system to avoid UI timeouts.

Gotchas and Tips

Pitfalls

  1. Command Not Found:

    • Ensure the commandName in YAML matches exactly the Symfony console command (including namespace if required).
    • Debug with php bin/console list to verify command names.
  2. Permission Denied:

    • Sonata’s security system may block access. Verify roles in security.yaml:
      access_control:
          - { path: ^/admin/integrations, roles: ROLE_USER }
      
  3. Template Overrides:

    • If overriding templates, clear the cache (php bin/console cache:clear) to see changes.
  4. Bundle Maturity:

    • The package is lightweight but lacks extensive documentation. Refer to Sonata’s admin bundle for advanced use cases.

Debugging

  • Check Command Execution: Enable Symfony’s debug toolbar or log command outputs:
    draw_sonata_integration:
        console:
            commands:
                reIndexSearch:
                    commandName: "fos:elastica:populate"
                    logOutput: true  # (Hypothetical feature; log manually if needed)
    
  • Service Container Issues: If commands fail, verify the service is properly autowired or tagged:
    php bin/console debug:container draw_sonata_integration.command_loader
    

Extension Points

  1. Custom Command Loaders: Implement Draw\SonataIntegrationBundle\Loader\CommandLoaderInterface to fetch commands from APIs or databases.

  2. 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,
        ]);
    }
    
  3. Event Listeners: Hook into Sonata’s events (e.g., sonata.admin.event.CRUD) to dynamically enable/disable commands:

    $event->getSubject()->addToCollection($command);
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware