backend.form.extendFields

Triggered in Backend\Widgets\Form.

Called after the form fields are defined

Example usage:

Event::listen('backend.form.extendFields', function((\Backend\Widgets\Form) $formWidget) {
    // Only for the User controller
    if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) {
        return;
    }

    // Only for the User model
    if (!$widget->model instanceof \RainLab\User\Models\User) {
        return;
    }

    // Add an extra birthday field
    $widget->addFields([
        'birthday' => [
            'label'   => 'Birthday',
            'comment' => 'Select the users birthday',
            'type'    => 'datepicker'
        ]
    ]);

    // Remove a Surname field
    $widget->removeField('surname');
});

Or

$formWidget->bindEvent('form.extendFields', function () use ((\Backend\Widgets\Form $formWidget)) {
    // Only for the User controller
    if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) {
        return;
    }

    // Only for the User model
    if (!$widget->model instanceof \RainLab\User\Models\User) {
        return;
    }

    // Add an extra birthday field
    $widget->addFields([
        'birthday' => [
            'label'   => 'Birthday',
            'comment' => 'Select the users birthday',
            'type'    => 'datepicker'
        ]
    ]);

    // Remove a Surname field
    $widget->removeField('surname');
});