Implemented a block editor for changing the layout of the page

This commit is contained in:
2026-04-04 01:17:05 +02:00
parent 0800f7664f
commit ff58e82497
41 changed files with 2706 additions and 298 deletions

View File

@@ -25,10 +25,13 @@ class PreregistrationPage extends Model
'thank_you_message',
'expired_message',
'ticketshop_url',
'post_submit_redirect_url',
'start_date',
'end_date',
'phone_enabled',
'background_image',
'background_overlay_color',
'background_overlay_opacity',
'logo_image',
'is_active',
];
@@ -61,6 +64,84 @@ class PreregistrationPage extends Model
return $this->hasMany(Subscriber::class);
}
public function blocks(): HasMany
{
return $this->hasMany(PageBlock::class)->orderBy('sort_order');
}
public function visibleBlocks(): HasMany
{
return $this->blocks()->where('is_visible', true);
}
public function getBlockByType(string $type): ?PageBlock
{
if ($this->relationLoaded('blocks')) {
return $this->blocks->firstWhere('type', $type);
}
return $this->blocks()->where('type', $type)->first();
}
public function getFormBlock(): ?PageBlock
{
return $this->getBlockByType('form');
}
public function getHeroBlock(): ?PageBlock
{
return $this->getBlockByType('hero');
}
/**
* Phone field is shown and validated when enabled in the form block (falls back to legacy column).
*/
public function isPhoneFieldEnabledForSubscribers(): bool
{
$form = $this->getBlockByType('form');
if ($form !== null) {
return (bool) data_get($form->content, 'fields.phone.enabled', false);
}
return (bool) $this->phone_enabled;
}
public function headlineForMeta(): string
{
$hero = $this->getHeroBlock();
if ($hero !== null) {
$headline = data_get($hero->content, 'headline');
if (is_string($headline) && $headline !== '') {
return $headline;
}
}
return $this->heading;
}
/**
* Keeps legacy DB columns aligned with hero/form blocks until those columns are dropped.
*/
public function syncLegacyContentColumnsFromBlocks(): void
{
$this->load('blocks');
$hero = $this->getHeroBlock();
$form = $this->getFormBlock();
$updates = [];
if ($hero !== null) {
$c = $hero->content ?? [];
$updates['heading'] = is_string($c['headline'] ?? null) ? $c['headline'] : $this->heading;
$sub = $c['subheadline'] ?? null;
$updates['intro_text'] = is_string($sub) ? $sub : null;
}
if ($form !== null) {
$updates['phone_enabled'] = (bool) data_get($form->content, 'fields.phone.enabled', false);
}
if ($updates !== []) {
$this->update($updates);
}
}
public function mailwizzConfig(): HasOne
{
return $this->hasOne(MailwizzConfig::class);