Skip to content

Commit b01cb92

Browse files
committed
Remove unnecessary code and fix checks
1 parent 2acd261 commit b01cb92

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

src/Filament/RelationManagers/FieldsRelationManager.php

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function form(Form $form): Form
8484
return;
8585
}
8686

87-
$set('config', $this->initializeConfig($state));
87+
$set('config', $this->getFieldTypeFormSchema($state));
8888
}),
8989

9090
Select::make('group')
@@ -118,43 +118,6 @@ public function form(Form $form): Form
118118
]);
119119
}
120120

121-
private function formatCustomFields(array $fields): array
122-
{
123-
return collect($fields)->mapWithKeys(function ($field, $key) {
124-
$parts = explode('\\', $field);
125-
$lastPart = end($parts);
126-
$formattedName = Str::title(Str::snake($lastPart, ' '));
127-
128-
return [$key => $formattedName];
129-
})->toArray();
130-
}
131-
132-
private function initializeDefaultConfig(string $fieldType): array
133-
{
134-
$className = 'Backstage\\Fields\\Fields\\' . Str::studly($fieldType);
135-
136-
if (! class_exists($className)) {
137-
return [];
138-
}
139-
140-
$fieldInstance = app($className);
141-
142-
return $fieldInstance::getDefaultConfig();
143-
}
144-
145-
private function initializeCustomConfig(string $fieldType): array
146-
{
147-
$className = Fields::getFields()[$fieldType] ?? null;
148-
149-
if (! class_exists($className)) {
150-
return [];
151-
}
152-
153-
$fieldInstance = app($className);
154-
155-
return $fieldInstance::getDefaultConfig();
156-
}
157-
158121
public function table(Table $table): Table
159122
{
160123
return $table
@@ -184,14 +147,16 @@ public function table(Table $table): Table
184147
Tables\Actions\CreateAction::make()
185148
->slideOver()
186149
->mutateFormDataUsing(function (array $data) {
187-
188-
$key = $this->ownerRecord->getKeyName() ?? 'id';
150+
$key = $this->ownerRecord->getKeyName();
151+
if ($key === '') {
152+
$key = 'id';
153+
}
189154

190155
return [
191156
...$data,
192157
'position' => Field::where('model_key', $key)->get()->max('position') + 1,
193158
'model_type' => 'setting',
194-
'model_key' => $this->ownerRecord->slug,
159+
'model_key' => $this->ownerRecord->slug ?? $key,
195160
];
196161
})
197162
->after(function (Component $livewire) {
@@ -202,8 +167,10 @@ public function table(Table $table): Table
202167
Tables\Actions\EditAction::make()
203168
->slideOver()
204169
->mutateRecordDataUsing(function (array $data) {
205-
206-
$key = $this->ownerRecord->getKeyName() ?? 'id';
170+
$key = $this->ownerRecord->getKeyName();
171+
if ($key === '') {
172+
$key = 'id';
173+
}
207174

208175
return [
209176
...$data,
@@ -221,8 +188,10 @@ public function table(Table $table): Table
221188
->getSchemaBuilder()
222189
->hasColumn($this->ownerRecord->getTable(), $record->valueColumn)
223190
) {
224-
225-
$key = $this->ownerRecord->getKeyName() ?? 'id';
191+
$key = $this->ownerRecord->getKeyName();
192+
if ($key === '') {
193+
$key = 'id';
194+
}
226195

227196
$this->ownerRecord->update([
228197
$record->valueColumn => collect($this->ownerRecord->{$record->valueColumn})->forget($record->{$key})->toArray(),

0 commit comments

Comments
 (0)