backend.form.extendFieldsBefore
Called before the form fields are defined
Example usage:
Event::listen('backend.form.extendFieldsBefore', function ((\Backend\Widgets\Form) $formWidget) {
// Check that we're extending the correct Form widget instance
if (
!($formWidget->getController() instanceof \Winter\User\Controllers\Users)
|| !($formWidget->model instanceof \Winter\User\Models\User)
|| $formWidget->isNested
) {
return;
}
// Here you can't use addFields() because it will throw you an exception because form is not yet created
// and it does not have tabs and fields
// For this example we will pretend that we want to add a new field named example_field
$formWidget->fields['example_field'] = [
'label' => 'Example field',
'comment' => 'Your example field',
'type' => 'text',
];
});
Or
$formWidget->bindEvent('form.extendFieldsBefore', function () use ((\Backend\Widgets\Form $formWidget)) {
// Check that we're extending the correct Form widget instance
if (
!($formWidget->getController() instanceof \Winter\User\Controllers\Users)
|| !($formWidget->model instanceof \Winter\User\Models\User)
|| $formWidget->isNested
) {
return;
}
// Here you can't use addFields() because it will throw you an exception because form is not yet created
// and it does not have tabs and fields
// For this example we will pretend that we want to add a new field named example_field
$formWidget->fields['example_field'] = [
'label' => 'Example field',
'comment' => 'Your example field',
'type' => 'text',
];
});
Usage
Triggers
Class or file | Line |
---|---|
Backend\Widgets\Form
|
544 |
Copyright © 2024 Winter CMS