Skip to content

Commit a5d64e7

Browse files
committed
feat: build schema tree
1 parent f053b09 commit a5d64e7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Filament/RelationManagers/FieldsRelationManager.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,23 @@ public static function getPluralModelLabel(): string
326326

327327
protected function getSchemaOptions(): array
328328
{
329-
$options = \Backstage\Fields\Models\Schema::where('model_key', $this->ownerRecord->getKey())
329+
$schemas = \Backstage\Fields\Models\Schema::where('model_key', $this->ownerRecord->getKey())
330330
->where('model_type', get_class($this->ownerRecord))
331331
->orderBy('position')
332-
->pluck('name', 'ulid')
333-
->toArray();
332+
->get();
333+
334+
return $this->buildSchemaTree($schemas);
335+
}
336+
337+
protected function buildSchemaTree($schemas, $parentId = null, $depth = 0): array
338+
{
339+
$options = [];
340+
$children = $schemas->where('parent_ulid', $parentId);
341+
342+
foreach ($children as $schema) {
343+
$options[$schema->ulid] = str_repeat('', $depth) . $schema->name;
344+
$options = $options + $this->buildSchemaTree($schemas, $schema->ulid, $depth + 1);
345+
}
334346

335347
return $options;
336348
}

0 commit comments

Comments
 (0)