backend.form.extendFieldsBefore

Triggered in Backend\Widgets\Form.

Called before the form fields are defined

Example usage:

Event::listen('backend.form.extendFieldsBefore', function((\Backend\Widgets\Form) $formWidget) {
    // You should always check to see if you're extending correct model/controller
    if (!$widget->model instanceof \Foo\Example\Models\Bar) {
        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
    $widget->fields['example_field'] = [
        'label' => 'Example field',
        'comment' => 'Your example field',
        'type' => 'text',
    ];
});

Or

$formWidget->bindEvent('form.extendFieldsBefore', function () use ((\Backend\Widgets\Form $formWidget)) {
    // You should always check to see if you're extending correct model/controller
    if (!$widget->model instanceof \Foo\Example\Models\Bar) {
        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
    $widget->fields['example_field'] = [
        'label' => 'Example field',
        'comment' => 'Your example field',
        'type' => 'text',
    ];
});