A section in the header set to #ffffff00 for the scrolled page still looked white: the sticky header element paints its own white surface and a shadow line underneath, so a transparent section showed that surface instead of the page, and the line could be neither recoloured nor removed. When a top-level header section defines a background of its own - normal, hover or scrolled - the header element now gets `has-own-surface` and paints nothing. A header without its own design keeps the white surface, so it does not turn see-through over the content. A text colour alone is not a surface, and a boxed column is not the whole header. The check is a Twig function rather than a controller variable because four paths render the header: page, archive, editor preview and area preview. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Twig;
|
|
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\TwigFunction;
|
|
|
|
/**
|
|
* Ob der Kopfbereich seine Fläche selbst gestaltet.
|
|
*
|
|
* Der klebende Kopf malt eine weiße Fläche mit Schattenlinie, damit ein Kopf ohne eigene
|
|
* Gestaltung beim Scrollen nicht über dem Inhalt durchscheint. Gibt eine Sektion des Kopfbereichs
|
|
* aber selbst einen Hintergrund vor - normal, beim Überfahren oder beim Scrollen -, lag diese
|
|
* Fläche dahinter: eine durchsichtige Sektion zeigte Weiß statt Seite, und die Linie ließ sich
|
|
* weder färben noch abschalten. Dann trägt die Sektion die Fläche allein.
|
|
*
|
|
* Eine Funktion statt einer Variablen, weil vier Wege den Kopf ausgeben - Seite, Archiv,
|
|
* Editor-Vorschau und Bereichs-Vorschau - und keiner davon vergessen werden darf.
|
|
*/
|
|
final class HeaderExtension extends AbstractExtension
|
|
{
|
|
/** Die Eigenschaften, die eine Fläche ausmachen. Eine Textfarbe allein ist keine. */
|
|
private const SURFACE = ['backgroundColor', 'gradientFrom', 'gradientTo', 'backgroundImage'];
|
|
|
|
public function getFunctions(): array
|
|
{
|
|
return [new TwigFunction('kant_header_surface', self::ownSurface(...))];
|
|
}
|
|
|
|
/**
|
|
* Nur Sektionen der obersten Ebene zählen: eine Spalte mit weißem Kasten um das Logo macht
|
|
* noch keinen Kopf, und ohne Fläche dahinter schiene der Rest über dem Inhalt durch.
|
|
*/
|
|
public static function ownSurface(?array $document): bool
|
|
{
|
|
foreach ($document['blocks'] ?? [] as $block) {
|
|
if ('section' !== ($block['type'] ?? null)) {
|
|
continue;
|
|
}
|
|
foreach ($block['style'] ?? [] as $values) {
|
|
if (!is_array($values)) {
|
|
continue;
|
|
}
|
|
foreach ([$values, $values['hover'] ?? [], $values['scrolled'] ?? []] as $state) {
|
|
foreach (self::SURFACE as $key) {
|
|
if (is_array($state) && '' !== (string) ($state[$key] ?? '')) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|