'DE', 'en' => 'EN', ]; /** Farbwelt der Seite (`interior` | `immobilien`), in mount() festgehalten. */ public string $world = 'interior'; /** @var array */ 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'); } }