Hook into before form schema

We have a form field that we want in 90% of all forms. Instead of manually having to add this to all form schemas I would like to find an automatic way to do this based on a certain condition. What would be the best way to achieve this? Have tried by extending classes etc but can't find a good solution to hook into the form schema and add fields in a parent class or so. Is there any other way we can hook in at the beginning or end of form schema? Or any other good solution that is SOLID? Any help is highly appreciated.
3 Replies
wyChoong
wyChoong8mo ago
defined a class that return the fields in array then include it in your form schema
$form->schema([
...StandardFormFields::getFormSchema(),
TextInput::make('field'),
])
$form->schema([
...StandardFormFields::getFormSchema(),
TextInput::make('field'),
])
prouse_
prouse_8mo ago
That's definitely a solution. I was just looking at a more clean solution where you don't always have to remember to include this.
wyChoong
wyChoong8mo ago
If there is a way for you to define once and forget it, then you always have to remember to exclude it when you don’t need it