Wohnung je Baustein wählen und Gitea-Runner-Kompatibilität herstellen
Deploy / test (push) Failing after 2m47s
Deploy / deploy (push) Skipped

This commit is contained in:
Lars Stommer committed 2026-10-26 08:23:14 +01:00
1 parent 3a0bb6e40f
commit abf0e9004b
8 files changed
+308 -27

No files matched your search

@@ -28,7 +28,7 @@ public static function configure(Schema $schema): Schema
->schema([
Builder::make('sections')
->hiddenLabel()
->blocks(fn (): array => app(SectionRegistry::class)->blocks())
->blocks(fn (callable $get): array => app(SectionRegistry::class)->blocks($get('site_id')))
->addActionLabel('Baustein hinzufügen')
->collapsible()
->collapsed()
+36 -11
View File
@@ -3,18 +3,19 @@
namespace App\Themes;
use App\Models\Appearance;
use App\Models\Property;
use App\Themes\Sections\Section;
use Filament\Forms\Components\Builder\Block;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\View as ViewFactory;
/**
* The section catalogue from config/themes.php: builder blocks for the admin and rendering for the website.
*
* Every placed section carries data.id (a stable UUID, see Page::assignSectionIds) so appearances can
* address it, and data.appearances (appearance ids; empty = always shown).
* address it, data.appearances (appearance ids; empty = always shown), and an optional data.property_id
* (an active property of this website; empty = primary property).
*/
class SectionRegistry
{
@@ -38,7 +39,7 @@ public function get(string $key): ?Section
/**
* @return list<Block>
*/
public function blocks(): array
public function blocks(?int $siteId = null): array
{
return array_values(array_map(
fn (string $class): Block => Block::make($class::key())
@@ -47,6 +48,17 @@ public function blocks(): array
->schema([
Hidden::make('id'),
...$class::schema(),
Select::make('property_id')
->label('Wohnung')
->placeholder('Hauptwohnung')
->helperText('Leer = Hauptwohnung dieser Website.')
->options(fn (): array => Property::query()
->where('site_id', $siteId)
->whereNotNull('site_id')
->where('is_active', true)
->orderBy('name')
->pluck('name', 'id')
->all()),
Select::make('appearances')
->label('Nur anzeigen im Erscheinungsbild')
->helperText('Leer = immer anzeigen. Z. B. ein Weihnachts-Baustein nur im Erscheinungsbild „Weihnachten“.')
@@ -70,11 +82,11 @@ public function isVisible(Theme $theme, array $data): bool
}
/**
* Renders the stored sections of a page; unknown or failing types are skipped (and reported),
* so a page never breaks because of one section.
* Prepares the stored sections for deferred rendering. Unknown types, missing views, hidden sections
* and unavailable property assignments are skipped.
*
* @param list<array{type: string, data?: array<string, mixed>}>|null $sections
* @return list<View>
* @return list<SectionView>
*/
public function render(Theme $theme, ?array $sections): array
{
@@ -85,11 +97,24 @@ public function render(Theme $theme, ?array $sections): array
continue;
}
$views[] = ViewFactory::make($section->view(), [
...$section->data($theme, $stored['data'] ?? []),
'theme' => $theme,
'sectionId' => $section::key().'-'.$index,
]);
$data = $stored['data'] ?? [];
$property = filled($data['property_id'] ?? null)
? $theme->site->properties()->where('is_active', true)->whereKey($data['property_id'])->first()
: $theme->property();
if (filled($data['property_id'] ?? null) && $property === null) {
continue;
}
$views[] = $theme->runForProperty($property, fn (): SectionView => new SectionView(
$theme,
$property,
ViewFactory::make($section->view(), [
...$section->data($theme, $data),
'theme' => $theme,
'sectionId' => $section::key().'-'.$index,
]),
));
}
return $views;
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Themes;
use App\Models\Property;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Contracts\View\View;
/**
* Keeps the section's property active when the page eventually renders its Blade view and partials.
*/
class SectionView implements Renderable
{
public function __construct(
private Theme $theme,
private ?Property $property,
private View $view,
) {}
public function render(): string
{
return $this->theme->runForProperty($this->property, fn (): string => $this->view->render());
}
}
+23
View File
@@ -174,6 +174,29 @@ public function property(): ?Property
return $this->property;
}
/**
* Run a section with its property, restoring the previous cache even when rendering fails.
*
* @template T
*
* @param callable(): T $callback
* @return T
*/
public function runForProperty(?Property $property, callable $callback): mixed
{
$previousProperty = $this->property;
$previousResolved = $this->propertyResolved;
$this->property = $property;
$this->propertyResolved = true;
try {
return $callback();
} finally {
$this->property = $previousProperty;
$this->propertyResolved = $previousResolved;
}
}
/**
* Published pages of a menu location ("main" or "footer").
*