Closed atmonshi closed 5 months ago
Added Configuration Support for Custom Schemas
config/zeus-bolt.php
. This key stores values in an array format to allow more flexibility and customizability.Integrated Custom Schema from Bolt into Various Methods
src/Concerns/Schemata.php
has been updated to incorporate custom schemas from Bolt within its methods. This implementation was done in two primary ways:
section-options
accordions have been modified to utilize a closure and now include custom schemas from Bolt.getTabsSchema
, getSectionsSchema
, getOptions
, and getOptionsHidden
now include a custom schema from Bolt, enhancing the overall functionality and adaptability of the methods.New Files Added to Support Custom Schemas
src/Contracts/CustomFormSchema.php
and src/Contracts/CustomSchema.php
, have been introduced to handle and support the custom schema feature.Enhanced the Bolt Facade with Custom Schema Methods
src/Facades/Bolt.php
has seen the addition of new methods - getCustomSchema
and getHiddenCustomSchema
. These methods allow for retrieving a custom or a hidden custom schema based on a specified hook, respectively.These changes were made to expand the flexibility, customizability, and robustness of the existing model by including support for custom schemas.
It worked like a charm for me once I determined that the issue with option validation was the reason it wasn't saving initially.
For some additional insight, my end goal is to create a sort of meta-field on the form fields so that I can define some custom functionality on FormSent
. For my uses, it ends up working something like this:
$event->response->fieldsResponses->each(function($fieldResponse){
$data_binding = explode('.', $fieldResponse->field->options['meta']['data_binding']); // ['Foo', 'name']
$model = (new $data_binding[0])([ $data_binding[1] => $fieldResponse->response]);
$model->save();
});
Wanted to include this here to help with any documentation needs and/or in case anyone needs to do something similar and finds this in the future.
Warning: Don't trust your user input explicitly like I'm doing in my example. That could open some pretty serious security holes. This is a simplified example. If you copy & paste this code without understanding the implications, I'm not responsible.
thank you @blhylton, can you share the schema you have or simple version of it, so I'll update the doc and add it as an example.
@atmonshi Sure thing. This is the one I was using for this particular example:
<?php
namespace App\Zeus;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\TextInput;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Bolt\Fields\FieldsContract;
class CustomSchema implements \LaraZeus\Bolt\Contracts\CustomSchema
{
public function make(?FieldsContract $field = null): Accordion
{
return Accordion::make('MetaFields')
->schema([
TextInput::make('options.meta.data_binding')
->label('Data Binding'),
]);
}
public function hidden(?FieldsContract $field = null): array
{
return [
Hidden::make('options.meta.data_binding'),
];
}
}
It's excessively simple because I was ultimately making sure it was going to work like I expected.
this is a continuance of the initial PR #300 by @blhylton, thank you so much.
will update the doc soon and add more details here...