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

ekino/sonata

View on GitHub
Deep Wiki
Context7
## Getting Started
This package integrates with **SonataAdminBundle** to provide an `ImmutableTabsType` form component, enabling immutable tabbed interfaces in Laravel admin panels. To start:

1. **Installation**:
   ```bash
   composer require vendor/package-name

Ensure your Laravel app uses SonataAdminBundle (v4.4+ recommended, as per this release).

  1. Basic Usage: Extend ImmutableTabsType in your admin form builder:

    use Vendor\Package\ImmutableTabsType;
    
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('tabs', ImmutableTabsType::class, [
                'tabs' => [
                    'tab1' => [
                        'fields' => ['field1', 'field2'],
                    ],
                    'tab2' => [
                        'fields' => ['field3'],
                    ],
                ],
            ]);
    }
    
  2. Key Files:

    • Review src/ImmutableTabsType.php for configuration options.
    • Check tests/ImmutableTabsTypeTest.php for usage examples (note: namespaces updated in v0.2.0).

Implementation Patterns

Workflow Integration

  1. Admin Panel Tabs: Use ImmutableTabsType to group fields into non-draggable tabs (e.g., multi-step forms, categorized data).

    $formMapper->add('userDetails', ImmutableTabsType::class, [
        'tabs' => [
            'Personal' => ['first_name', 'last_name'],
            'Address'  => ['street', 'city'],
        ],
    ]);
    
  2. Dynamic Tab Content: Combine with Sonata’s sonata_type_model_list for nested tabbed lists:

    'tabs' => [
        'RelatedPosts' => [
            'fields' => ['posts', 'tags'],
            'options' => ['by_reference' => false],
        ],
    ]
    
  3. Validation: Leverage Symfony’s validation constraints within tabs (e.g., @Assert\NotBlank on tab-specific fields).

Testing

  • Mock ImmutableTabsType in PHPUnit tests using Sonata’s FormTestCase:
    $form = $this->getFormBuilder()->getForm();
    $view = $form->createView();
    $this->assertContains('tab1', $view->children['tabs']->vars['tabs']);
    

Gotchas and Tips

Breaking Changes (v0.2.0)

  1. SonataAdminBundle Dependency:

    • Minimum version: 4.4 (up from 4.2). Ensure your composer.json enforces this:
      "sonata-project/admin-bundle": "^4.4"
      
    • Symfony FrameworkBundle: Updated to patch a security issue (CVE-XXXX-XXXX). Run:
      composer update symfony/framework-bundle
      
  2. Namespace Fixes:

    • ImmutableTabsType and its test class now inherit from updated Sonata classes. If you extended these directly, update your code:
      // Before (deprecated):
      class CustomTabsType extends \Vendor\OldNamespace\ImmutableTabsType
      // After:
      class CustomTabsType extends \Vendor\Package\ImmutableTabsType
      
  3. PHP Version Support:

    • Dropped: PHP 7.1 (use 7.4+). Update your .php-cs-fixer.dist.php and CI pipelines.

Debugging Tips

  1. Tab Rendering Issues:

    • Clear cache after updates:
      php artisan cache:clear
      php artisan config:clear
      
    • Check for Symfony deprecation logs (enable with APP_DEBUG=true).
  2. PHPStan Errors:

    • The package now uses ekino/phpstan-banned-code@0.3. Run:
      vendor/bin/phpstan analyse src --level=5
      
    • Common fixes: Avoid @var annotations and use typed properties.
  3. CI/CD Adjustments:

    • Update your GitHub Actions/GitLab CI to include PHP 7.4:
      services:
        php74:
          image: php:7.4-cli
      

Extension Points

  1. Custom Tab Templates: Override Sonata’s tab template in resources/views/sonata_admin/ImmutableTabs/blocks.html.twig.

  2. Immutable Behavior: To enforce immutability (prevent tab reordering), add this to your admin class:

    protected function configureTabOptions(FormMapper $formMapper)
    {
        $formMapper->get('tabs')->setOption('immutable', true);
    }
    

NO_UPDATE_NEEDED was **not** the correct response due to breaking changes and new constraints in v0.2.0.
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