Startseite frei gestalten, Neuigkeiten-Block mit Kategorien-Filter (0.26.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m21s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m55s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m34s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 09:38:18 +00:00
parent 6290e09074
commit 2c96fcce1c
151 changed files with 1515 additions and 317 deletions

View file

@ -24,6 +24,7 @@ class Blocks
'content' => 'Inhalt',
'media' => 'Medien',
'dynamic' => 'Dynamisch',
'homepage' => 'Startseite',
];
/** @var array<string, BlockType> */
@ -61,9 +62,13 @@ class Blocks
/**
* @return list<array<string, mixed>>
*/
public function forEditor(): array
/**
* @param bool $homepage Startseiten-Editor: auch die Blöcke der Gruppe „Startseite“ (Kacheln)
* @return list<array<string, mixed>>
*/
public function forEditor(bool $homepage = false): array
{
return array_values(array_map(fn (BlockType $type) => $type->toArray(), $this->all()));
return array_values(array_map(fn (BlockType $type) => $type->toArray(), array_filter($this->all(), fn (BlockType $type) => $homepage || $type->group !== 'homepage')));
}
/**

View file

@ -48,6 +48,16 @@ final class Field
return new self($name, 'select', $label, ['choices' => $choices, 'default' => $default]);
}
/**
* Mehrfachauswahl (Häkchen), z. B. mehrere Kategorien.
*
* @param array<string, string>|Closure(): array<string, string> $choices
*/
public static function multiselect(string $name, string $label, array|Closure $choices): self
{
return new self($name, 'multiselect', $label, ['choices' => $choices, 'default' => []]);
}
public static function toggle(string $name, string $label, bool $default = false): self
{
return new self($name, 'toggle', $label, ['default' => $default]);
@ -138,6 +148,7 @@ final class Field
'text', 'textarea' => mb_substr(trim(is_scalar($value) ? (string) $value : ''), 0, $this->options['max']),
'html' => app(RichText::class)->sanitize(is_string($value) ? mb_substr($value, 0, 200_000) : ''),
'select' => $this->sanitizeChoice($value),
'multiselect' => $this->sanitizeChoices($value),
'toggle' => (bool) $value,
'number' => max($this->options['min'], min($this->options['max'], is_numeric($value) ? (int) $value : $this->options['default'])),
'url' => self::safeUrl($value),
@ -166,6 +177,19 @@ final class Field
return preg_match('#^[a-z0-9.-]+\.[a-z]{2,}(/|$)#i', $url) ? 'https://'.$url : '';
}
/**
* @return list<string>
*/
private function sanitizeChoices(mixed $value): array
{
$choices = $this->options['choices'] instanceof Closure ? ($this->options['choices'])() : $this->options['choices'];
return array_values(array_unique(array_filter(
array_map(fn ($v) => is_scalar($v) ? (string) $v : '', is_array($value) ? $value : []),
fn (string $v) => $v !== '' && array_key_exists($v, $choices),
)));
}
private function sanitizeChoice(mixed $value): ?string
{
$choices = $this->options['choices'] instanceof Closure ? ($this->options['choices'])() : $this->options['choices'];