backend.form.extendFieldsBefore

Triggered in: Backend\Widgets\Form.php

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 (!$formWidget->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
    $formWidget->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 (!$formWidget->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
    $formWidget->fields['example_field'] = [
        'label' => 'Example field',
        'comment' => 'Your example field',
        'type' => 'text',
    ];
});

Keep informed

Sign up to our newsletter to receive updates on Winter CMS releases, new features in the works, and much more.
We'll never spam or give this address away.

Latest blog post

October CMS as you know it is Dead

Published April 12, 2021
We regret to inform you that October CMS as you have known it for the past 7 years is no more. The founders have decided to make it a paid proprietary product; unfortunately abandoning the open source community in the process as "source partially available" is not open source. The core maintainers of the project have forked, and will continue development as Winter CMS....

View this post Read all posts

Latest Winter CMS release

v1.1.3

Released April 26, 2021
3 UX/UI Improvements, 19 API Changes, 23 Bug Fixes, 3 Security Improvements, 4 Translation Improvements, 1 Community Improvement, 2 Dependencies

View details View all releases