chore: commit remaining workspace changes
This commit is contained in:
@@ -149,7 +149,7 @@ final class ArtworkPageController extends Controller
|
||||
'md' => $thumbMd,
|
||||
'lg' => $thumbLg,
|
||||
'xl' => $thumbXl,
|
||||
], $canonical)->toArray();
|
||||
], $canonical, $this->artworkBreadcrumbs($artwork, $canonical))->toArray();
|
||||
|
||||
$categoryIds = $artwork->categories->pluck('id')->filter()->values();
|
||||
$tagIds = $artwork->tags->pluck('id')->filter()->values();
|
||||
@@ -364,6 +364,70 @@ final class ArtworkPageController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{name: string, url: string}>
|
||||
*/
|
||||
private function artworkBreadcrumbs(Artwork $artwork, string $canonical): array
|
||||
{
|
||||
$primaryCategory = $artwork->categories
|
||||
->sortBy(fn ($category) => [
|
||||
(int) ($category->sort_order ?? 0),
|
||||
(string) ($category->name ?? ''),
|
||||
])
|
||||
->first();
|
||||
|
||||
if ($primaryCategory === null) {
|
||||
return [
|
||||
['name' => 'Explore', 'url' => url('/explore')],
|
||||
['name' => html_entity_decode((string) $artwork->title, ENT_QUOTES | ENT_HTML5, 'UTF-8'), 'url' => $canonical],
|
||||
];
|
||||
}
|
||||
|
||||
$contentType = $primaryCategory->contentType;
|
||||
$chain = collect();
|
||||
$current = $primaryCategory;
|
||||
|
||||
while ($current !== null) {
|
||||
$chain->prepend($current);
|
||||
$current = $current->relationLoaded('parent') ? $current->parent : null;
|
||||
}
|
||||
|
||||
$breadcrumbs = [];
|
||||
$contentTypeSlug = trim((string) ($contentType?->slug ?? ''));
|
||||
$contentTypeName = trim((string) ($contentType?->name ?? ''));
|
||||
|
||||
if ($contentTypeSlug !== '' && $contentTypeName !== '') {
|
||||
$breadcrumbs[] = [
|
||||
'name' => $contentTypeName,
|
||||
'url' => url('/' . $contentTypeSlug),
|
||||
];
|
||||
}
|
||||
|
||||
$pathSegments = [];
|
||||
|
||||
foreach ($chain as $category) {
|
||||
$slug = trim((string) ($category->slug ?? ''));
|
||||
$name = trim((string) ($category->name ?? ''));
|
||||
|
||||
if ($slug === '' || $name === '' || $contentTypeSlug === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pathSegments[] = $slug;
|
||||
$breadcrumbs[] = [
|
||||
'name' => $name,
|
||||
'url' => url('/' . $contentTypeSlug . '/' . implode('/', $pathSegments)),
|
||||
];
|
||||
}
|
||||
|
||||
$breadcrumbs[] = [
|
||||
'name' => html_entity_decode((string) $artwork->title, ENT_QUOTES | ENT_HTML5, 'UTF-8'),
|
||||
'url' => $canonical,
|
||||
];
|
||||
|
||||
return $breadcrumbs;
|
||||
}
|
||||
|
||||
/** Silently catch suggestion query failures so error page never crashes. */
|
||||
private function safeSuggestions(callable $fn): mixed
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user