|
16 | 16 | use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneCloseType; |
17 | 17 | use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneGroupCloseType; |
18 | 18 | use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneGroupOpenType; |
| 19 | +use Stringable; |
19 | 20 | use Symfony\Component\String\Slugger\AsciiSlugger; |
20 | 21 | use Symfony\Component\Uid\Ulid; |
21 | 22 |
|
@@ -78,7 +79,10 @@ private function validateLayoutConfiguration(FieldCollection $fields): void |
78 | 79 | } |
79 | 80 |
|
80 | 81 | if ($theFirstFieldWhichIsATabOrColumn->isFormColumn() && $fieldDto->isFormTab()) { |
81 | | - throw new \InvalidArgumentException(sprintf('When using form columns, you can\'t define tabs inside columns (but you can define columns inside tabs). Move the tab "%s" outside any column.', $fieldDto->getLabel())); |
| 82 | + $label = $fieldDto->getLabel(); |
| 83 | + $labelAsString = (\is_string($label) || $label instanceof Stringable) ? (string) $label : ''; |
| 84 | + |
| 85 | + throw new \InvalidArgumentException(sprintf('When using form columns, you can\'t define tabs inside columns (but you can define columns inside tabs). Move the tab "%s" outside any column.', $labelAsString)); |
82 | 86 | } |
83 | 87 | } |
84 | 88 | } |
@@ -181,7 +185,13 @@ private function linearizeLayoutConfiguration(FieldCollection $fields): void |
181 | 185 |
|
182 | 186 | if ($fieldDto->isFormTab()) { |
183 | 187 | $isTabActive = 0 === \count($tabs); |
184 | | - $tabId = sprintf('tab-%s', $fieldDto->getLabel() ? $slugger->slug(strip_tags($fieldDto->getLabel()))->lower()->toString() : ++$tabsWithoutLabelCounter); |
| 188 | + $label = $fieldDto->getLabel(); |
| 189 | + $tabId = sprintf( |
| 190 | + 'tab-%s', |
| 191 | + (\is_string($label) || $label instanceof Stringable) |
| 192 | + ? $slugger->slug(strip_tags((string) $label))->lower()->toString() |
| 193 | + : ++$tabsWithoutLabelCounter |
| 194 | + ); |
185 | 195 | $fieldDto->setCustomOption(FormField::OPTION_TAB_ID, $tabId); |
186 | 196 | $fieldDto->setCustomOption(FormField::OPTION_TAB_IS_ACTIVE, $isTabActive); |
187 | 197 |
|
@@ -395,6 +405,7 @@ public static function createFromFieldDtos(?FieldCollection $fieldDtos): FieldLa |
395 | 405 | $tabs[$fieldDto->getUniqueId()] = $fieldDto; |
396 | 406 | } else { |
397 | 407 | if ($hasTabs) { |
| 408 | + /** @phpstan-ignore-next-line offsetAccess.nonOffsetAccessible */ |
398 | 409 | $fields[$currentTab->getUniqueId()][] = $fieldDto; |
399 | 410 | } else { |
400 | 411 | $fields[] = $fieldDto; |
|
0 commit comments