## 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).
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'],
],
],
]);
}
Key Files:
src/ImmutableTabsType.php for configuration options.tests/ImmutableTabsTypeTest.php for usage examples (note: namespaces updated in v0.2.0).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'],
],
]);
Dynamic Tab Content:
Combine with Sonata’s sonata_type_model_list for nested tabbed lists:
'tabs' => [
'RelatedPosts' => [
'fields' => ['posts', 'tags'],
'options' => ['by_reference' => false],
],
]
Validation:
Leverage Symfony’s validation constraints within tabs (e.g., @Assert\NotBlank on tab-specific fields).
ImmutableTabsType in PHPUnit tests using Sonata’s FormTestCase:
$form = $this->getFormBuilder()->getForm();
$view = $form->createView();
$this->assertContains('tab1', $view->children['tabs']->vars['tabs']);
SonataAdminBundle Dependency:
composer.json enforces this:
"sonata-project/admin-bundle": "^4.4"
composer update symfony/framework-bundle
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
PHP Version Support:
.php-cs-fixer.dist.php and CI pipelines.Tab Rendering Issues:
php artisan cache:clear
php artisan config:clear
APP_DEBUG=true).PHPStan Errors:
ekino/phpstan-banned-code@0.3. Run:
vendor/bin/phpstan analyse src --level=5
@var annotations and use typed properties.CI/CD Adjustments:
services:
php74:
image: php:7.4-cli
Custom Tab Templates:
Override Sonata’s tab template in resources/views/sonata_admin/ImmutableTabs/blocks.html.twig.
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.
How can I help you explore Laravel packages today?