|
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,9 @@ 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 | + $labelAsString = (\is_string($label) || $label instanceof Stringable) ? (string) $label : ''; |
| 190 | + $tabId = sprintf('tab-%s', '' !== $labelAsString ? $slugger->slug(strip_tags($labelAsString))->lower()->toString() : ++$tabsWithoutLabelCounter); |
185 | 191 | $fieldDto->setCustomOption(FormField::OPTION_TAB_ID, $tabId); |
186 | 192 | $fieldDto->setCustomOption(FormField::OPTION_TAB_IS_ACTIVE, $isTabActive); |
187 | 193 |
|
@@ -395,6 +401,7 @@ public static function createFromFieldDtos(?FieldCollection $fieldDtos): FieldLa |
395 | 401 | $tabs[$fieldDto->getUniqueId()] = $fieldDto; |
396 | 402 | } else { |
397 | 403 | if ($hasTabs) { |
| 404 | + /** @phpstan-ignore-next-line offsetAccess.nonOffsetAccessible */ |
398 | 405 | $fields[$currentTab->getUniqueId()][] = $fieldDto; |
399 | 406 | } else { |
400 | 407 | $fields[] = $fieldDto; |
|
0 commit comments