I'm trying to add a new Tab in entry elements from my module using events.
Event::on(
FieldLayout::class,
FieldLayout::EVENT_DEFINE_NATIVE_FIELDS,
static function(DefineFieldLayoutFieldsEvent $event) {
/** @var FieldLayout $fieldLayout */
$fieldLayout = $event->sender;
$tabs = $fieldLayout->getTabs();
$layoutElements = [
new TextField([
'label' => 'My Description',
'attribute' => 'description',
'mandatory' => true,
'instructions' => 'Enter a description.',
])
];
$newTab = new FieldLayoutTab();
$newTab->name = 'Audit';
$newTab->layoutId = $fieldLayout->id;
$newTab->setLayout($fieldLayout);
$newTab->setElements($layoutElements);
$fieldLayout->setTabs([...$tabs, $newTab]);
}
);
What is the correct way to add a new tab in entry ?