Is it possible to get form from resource and add it to createOptionForm?
As the title says, I don't like having to repeat the content of the form in a section and in any other select field that has a createOptionForm method on it.
I guess I can just put it on a helper function in a service class or something but I was wondering if it would be possible to do it in a nicer way.
Solution:Jump to solution
So we do it like this within the activity plugin:
$form = static::getResource()::form(new Form($this));
You could also put a static array return function within the resource file and call that single function each time π...
5 Replies
Sure, get the Resource and then the form as a method call?
Solution
So we do it like this within the activity plugin:
$form = static::getResource()::form(new Form($this));
You could also put a static array return function within the resource file and call that single function each time π
Thanks! I actually went for the second option, nice and clean.
Welcomes, itβs what I do. You could also look at building a schema folder and containing all your forms for each model type in here and structure it that way π
For a nice online solution, this is what i am using now.
'''
->createOptionForm(fn(Form $form) => OrderVatResource::form($form))
'''