b2in/app/Livewire/Web/Components/Ui/Header.php
Kevin Adametz a661a68913 Hotfix: Livewire-UI-Komponenten im Ordner Ui (wie der Namespace)
Der Ordner hieß im Repository UI, der Namespace App\Livewire\Web\Components\Ui. Auf dem
Mac fällt das nicht auf, auf Linux findet der Autoloader die Klassen nicht: Header,
Footer usw. rendern ohne Klasse (500, Undefined variable $logoPath). Wächtertest prüft
Pfad und Namespace auf gleiche Schreibweise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 09:11:39 +00:00

130 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Livewire\Web\Components\Ui;
use Livewire\Component;
class Header extends Component
{
public $isMobileMenuOpen = false;
public $domainName;
public $domainUrl;
public $content = [];
public $currentLocale;
public $availableLocales = [
'de' => 'DE',
'en' => 'EN',
];
/** Farbwelt der Seite (`interior` | `immobilien`), in mount() festgehalten. */
public string $world = 'interior';
/** @var array<string, array{label: string, url: string, active: bool}> */
public array $worlds = [];
public string $logoPath = '';
/** Pfad der Seite, in mount() festgehalten – ein Livewire-Request traegt ihn nicht mehr. */
public string $currentPath = '/';
/** Ziel des Kontakt-Buttons: /contact (Interior) bzw. /immobilien/kontakt (Immobilien). */
public string $contactUrl = '';
public function mount(): void
{
$this->domainName = \App\Helpers\ThemeHelper::getDomainName();
$this->domainUrl = \App\Helpers\ThemeHelper::getDomainUrl();
$this->currentLocale = app()->getLocale();
$this->world = b2in_world();
$this->worlds = b2in_worlds($this->world);
$this->logoPath = \App\Helpers\ThemeHelper::getLogoPath('positive', $this->world);
$this->currentPath = '/'.ltrim(request()->path(), '/');
$this->contactUrl = route($this->world === 'immobilien' ? 'immobilien.contact' : 'contact');
// Jede Welt hat ihre eigene Navigation (CMS: global.header bzw. global.header_immobilien).
$this->content = cms_theme_section($this->world === 'immobilien' ? 'header_immobilien' : 'header');
// Ensure required keys exist
if (!isset($this->content['portal_login'])) {
$this->content['portal_login'] = 'Portal Login';
}
if (!isset($this->content['navigation']) || !is_array($this->content['navigation'])) {
$this->content['navigation'] = [];
}
// Referenzen lassen sich im CMS ausblenden; dann verschwindet auch der Menüpunkt.
if (! references_page_enabled()) {
$this->content['navigation'] = array_values(array_filter(
$this->content['navigation'],
fn ($item) => rtrim(parse_url((string) ($item['url'] ?? ''), PHP_URL_PATH) ?? '', '/') !== '/referenzen',
));
}
}
public function switchLanguage(string $locale): mixed
{
if (array_key_exists($locale, $this->availableLocales)) {
app()->setLocale($locale);
session(['locale' => $locale]);
$this->currentLocale = $locale;
$referer = request()->header('Referer') ?? '/';
return redirect()->to($referer);
}
return null;
}
public function toggleMobileMenu(): void
{
$this->isMobileMenuOpen = ! $this->isMobileMenuOpen;
}
public function closeMobileMenu(): void
{
$this->isMobileMenuOpen = false;
}
/**
* Aktiver Navigationspunkt: exakter Treffer, sonst der laengste Eintrag, dessen Pfad ein
* Praefix der Seite ist. So markiert /immobilien/magazin nur „Magazin“, nicht auch
* „Immobilien“. Anker (#…) zaehlen nicht zum Pfad.
*/
public function isActiveRoute($url): bool
{
$path = $this->navPath((string) $url);
if ($this->currentPath === $path) {
return true;
}
if ($path === '/' || ! str_starts_with($this->currentPath, rtrim($path, '/').'/')) {
return false;
}
foreach ($this->content['navigation'] ?? [] as $navItem) {
$other = $this->navPath((string) ($navItem['url'] ?? ''));
if ($other === $this->currentPath) {
return false;
}
if (strlen($other) > strlen($path) && str_starts_with($this->currentPath, rtrim($other, '/').'/')) {
return false;
}
}
return true;
}
private function navPath(string $url): string
{
$path = (string) (parse_url($url, PHP_URL_PATH) ?? '/');
return '/'.ltrim($path, '/');
}
public function render()
{
return view('livewire.web.components.ui.header');
}
}