Add Page Section Builder functionality: Introduced a new section builder for dynamic page sections in the Filament Admin panel, allowing users to add various section types with flexible key-value data management. Enhanced the Page model with methods for parsed sections and section data retrieval. Updated localization files to support new section-related terms and added comprehensive documentation for usage and best practices.

This commit is contained in:
Ümit Tunç
2025-10-30 16:28:50 -03:00
parent 0615bbecb1
commit 22b39d94a9
7 changed files with 871 additions and 1 deletions
+36
View File
@@ -88,4 +88,40 @@ class Page extends Model
return null;
}
/**
* Get sections with parsed data as associative array
*/
public function getParsedSectionsAttribute()
{
if (!$this->sections || !is_array($this->sections)) {
return [];
}
return collect($this->sections)->map(function ($section) {
if (!isset($section['data']) || !is_array($section['data'])) {
return $section;
}
// Convert key-value-type array to associative array
$parsedData = collect($section['data'])->pluck('value', 'key')->toArray();
return [
'type' => $section['type'] ?? null,
'data' => $parsedData,
];
})->toArray();
}
/**
* Get a specific section's data by type
*/
public function getSectionData(string $type, int $index = 0): ?array
{
$sections = $this->parsed_sections;
$matchingSections = array_filter($sections, fn($s) => ($s['type'] ?? null) === $type);
$matchingSections = array_values($matchingSections);
return $matchingSections[$index] ?? null;
}
}