b2in/app/Livewire/Web/Components/Sections/BrandDetail.php

89 lines
2.6 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\Sections;
use App\Models\CmsBrand;
use Livewire\Component;
class BrandDetail extends Component
{
public string $slug = '';
/** @var array<string, mixed> */
public array $brand = [];
/** @var array<int, array<string, mixed>> */
public array $otherBrands = [];
/**
* Galerie getrennt nach realisierten Projekten und Inspirationen.
*
* @var array{projects: array<int, array<string, mixed>>, inspirations: array<int, array<string, mixed>>}
*/
public array $gallery = ['projects' => [], 'inspirations' => []];
public function mount(string $slug): void
{
$brands = CmsBrand::forFrontend();
abort_unless(isset($brands[$slug]), 404);
$this->slug = $slug;
$this->brand = $brands[$slug];
$this->gallery = CmsBrand::groupGallery($this->brand['gallery'] ?? []);
$this->otherBrands = collect($brands)
->reject(fn (array $brand, string $key) => $key === $slug)
->values()
->all();
$craft = $this->craftSection($slug, $brands);
if ($craft !== null) {
$this->brand['sections'][] = $craft;
}
}
/**
* Gemeinsamer Handwerk-Abschluss (Lang-Sektion `brand_craft`, Nachtrag 15): steht als letzter
* Abschnitt auf jeder Markenseite – außer auf der Seite der Handwerksmarke selbst. Der Link
* dorthin erscheint nur, wenn diese Marke veröffentlicht ist und eine Detailseite hat.
*
* @param array<string, array<string, mixed>> $brands
* @return array<string, mixed>|null
*/
private function craftSection(string $slug, array $brands): ?array
{
$content = cms_theme_section('brand_craft');
if (! is_array($content)) {
return null;
}
$craftSlug = (string) ($content['brand_slug'] ?? '');
if ($craftSlug !== '' && $craftSlug === $slug) {
return null;
}
$sections = CmsBrand::normalizeSections([$content]);
if ($sections === []) {
return null;
}
$section = $sections[0];
$section['anchor'] = 'handwerk';
if ($craftSlug !== '' && ! empty($brands[$craftSlug]['has_detail_page'])) {
$section['link'] = route('marken.show', ['slug' => $craftSlug]);
$section['link_text'] = (string) ($content['link_text'] ?? $brands[$craftSlug]['name'] ?? '');
}
return $section;
}
public function render()
{
return view('livewire.web.components.sections.brand-detail');
}
}