Enhance settings management: Added support for new form types including color picker, code editor, rich editor, markdown editor, tags input, checkbox list, radio buttons, toggle buttons, and slider in the SettingForm. Updated the Setting model to handle these new types and modified the migration to include them in the type enum. Enhanced localization files to support new type labels in both English and Turkish.
This commit is contained in:
@@ -10,6 +10,17 @@ use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\ColorPicker;
|
||||
use Filament\Forms\Components\CodeEditor;
|
||||
use Filament\Forms\Components\CodeEditor\Enums\Language as CodeEditorLanguage;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Forms\Components\TagsInput;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Components\Slider;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
@@ -61,6 +72,16 @@ class SettingForm
|
||||
'file' => __('settings.type_file'),
|
||||
'date' => __('settings.type_date'),
|
||||
'datetime' => __('settings.type_datetime'),
|
||||
'color_picker' => __('settings.type_color_picker'),
|
||||
'code_editor' => __('settings.type_code_editor'),
|
||||
'rich_editor' => __('settings.type_rich_editor'),
|
||||
'markdown_editor' => __('settings.type_markdown_editor'),
|
||||
'tags_input' => __('settings.type_tags_input'),
|
||||
'checkbox_list' => __('settings.type_checkbox_list'),
|
||||
'radio' => __('settings.type_radio'),
|
||||
'toggle_buttons' => __('settings.type_toggle_buttons'),
|
||||
'slider' => __('settings.type_slider'),
|
||||
'key_value' => __('settings.type_key_value'),
|
||||
])
|
||||
->live()
|
||||
->afterStateUpdated(fn (Set $set) => $set('value', null)),
|
||||
@@ -85,10 +106,10 @@ class SettingForm
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => !in_array($get('type'), ['boolean', 'file', 'date', 'datetime', 'array']))
|
||||
->visible(fn (Get $get) => in_array($get('type'), ['string', 'text', 'json']))
|
||||
->rows(fn (Get $get) => $get('type') === 'text' ? 5 : 3)
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && !in_array($record->type, ['boolean', 'file', 'date', 'datetime', 'array'])) {
|
||||
if ($record && in_array($record->type, ['string', 'text', 'json'])) {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
@@ -193,6 +214,176 @@ class SettingForm
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
ColorPicker::make('value_color_picker')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'color_picker')
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'color_picker') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
CodeEditor::make('value_code_editor')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'code_editor')
|
||||
->language(CodeEditorLanguage::Php)
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'code_editor') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
RichEditor::make('value_rich_editor')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'rich_editor')
|
||||
->fileAttachmentsDisk('public')
|
||||
->fileAttachmentsDirectory('settings')
|
||||
->toolbarButtons([
|
||||
'attachFiles',
|
||||
'blockquote',
|
||||
'bold',
|
||||
'bulletList',
|
||||
'codeBlock',
|
||||
'h2',
|
||||
'h3',
|
||||
'italic',
|
||||
'link',
|
||||
'orderedList',
|
||||
'redo',
|
||||
'strike',
|
||||
'underline',
|
||||
'undo',
|
||||
])
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'rich_editor') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
MarkdownEditor::make('value_markdown_editor')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'markdown_editor')
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'markdown_editor') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
TagsInput::make('value_tags_input')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'tags_input')
|
||||
->separator(',')
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'tags_input') {
|
||||
$decoded = json_decode($record->value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return is_array($state) ? $state : [];
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
CheckboxList::make('value_checkbox_list')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'checkbox_list')
|
||||
->options(fn () => [
|
||||
'option1' => __('settings.checkbox_option_1'),
|
||||
'option2' => __('settings.checkbox_option_2'),
|
||||
'option3' => __('settings.checkbox_option_3'),
|
||||
])
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'checkbox_list') {
|
||||
$decoded = json_decode($record->value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return is_array($state) ? $state : [];
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
Radio::make('value_radio')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'radio')
|
||||
->options(fn () => [
|
||||
'option1' => __('settings.radio_option_1'),
|
||||
'option2' => __('settings.radio_option_2'),
|
||||
'option3' => __('settings.radio_option_3'),
|
||||
])
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'radio') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
ToggleButtons::make('value_toggle_buttons')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'toggle_buttons')
|
||||
->options(fn () => [
|
||||
'option1' => __('settings.toggle_option_1'),
|
||||
'option2' => __('settings.toggle_option_2'),
|
||||
'option3' => __('settings.toggle_option_3'),
|
||||
])
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'toggle_buttons') {
|
||||
return $record->value;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
Slider::make('value_slider')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'slider')
|
||||
->range(minValue: 0, maxValue: 100)
|
||||
->step(1)
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'slider') {
|
||||
return (int) $record->value;
|
||||
}
|
||||
return $state ?? 0;
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
KeyValue::make('value_key_value')
|
||||
->label(__('settings.value'))
|
||||
->helperText(__('settings.value_helper'))
|
||||
->required()
|
||||
->visible(fn (Get $get) => $get('type') === 'key_value')
|
||||
->formatStateUsing(function ($state, $record) {
|
||||
if ($record && $record->type === 'key_value') {
|
||||
$decoded = json_decode($record->value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return is_array($state) ? $state : [];
|
||||
})
|
||||
->columnSpanFull(),
|
||||
|
||||
Toggle::make('is_active')
|
||||
->label(__('settings.is_active'))
|
||||
->helperText(__('settings.is_active_helper'))
|
||||
|
||||
Reference in New Issue
Block a user