Files
citrus/app/Support/PageTemplateHero.php
T

122 lines
3.3 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\Support;
use App\Models\Page;
class PageTemplateHero
{
public static function config(?string $template): ?array
{
if (! filled($template)) {
return null;
}
$heroes = config('page_templates.heroes', []);
return $heroes[$template] ?? null;
}
public static function hasHero(?string $template): bool
{
return filled(static::imagePath($template));
}
public static function imagePath(?string $template): ?string
{
return static::config($template)['image'] ?? null;
}
public static function webpPath(?string $template): ?string
{
return static::config($template)['webp'] ?? null;
}
public static function url(?string $template): ?string
{
$path = static::imagePath($template);
return $path ? asset($path) : null;
}
public static function webpUrl(?string $template): ?string
{
$path = static::webpPath($template);
return $path ? asset($path) : null;
}
public static function featuredStoragePath(Page $page): ?string
{
$value = $page->featured_image;
if (blank($value)) {
return null;
}
if (is_array($value)) {
$value = $value[0] ?? null;
}
return is_string($value) && $value !== '' ? $value : null;
}
public static function urlForPage(Page $page): ?string
{
if ($path = static::featuredStoragePath($page)) {
return asset('storage/' . $path);
}
return static::url($page->template);
}
/**
* Hero alanı için görsel verisi (yüklenen öne çıkan görsel veya şablon varsayılanı).
*
* @return array{image: string, webp?: string, width?: int, height?: int, from_upload: bool}|null
*/
public static function resolveForPage(?Page $page, ?string $templateFallback = null): ?array
{
if ($page && ($path = static::featuredStoragePath($page))) {
return [
'image' => asset('storage/' . $path),
'from_upload' => true,
];
}
$template = $page?->template ?? $templateFallback;
$config = static::config($template);
if (! $config) {
return null;
}
return array_merge($config, ['from_upload' => false]);
}
/**
* @return array<string, string>
*/
public static function templateFormOptions(): array
{
$base = [
'default' => __('pages.template_default'),
'landing' => __('pages.template_landing'),
'blog' => __('pages.template_blog'),
'contact' => __('pages.template_contact'),
'home' => 'Home',
'corporate.testimonials' => 'Müşteri Görüşleri (Kurumsal)',
'corporate.logos' => 'Logolarımız (Kurumsal)',
'corporate.partners' => 'Çözüm Ortaklarımız (Kurumsal)',
'corporate.bank-accounts' => 'Banka Bilgilerimiz (Kurumsal)',
'corporate.online-payment' => 'Online Ödeme (Kurumsal)',
];
$fromConfig = collect(config('page_templates.labels', []))
->mapWithKeys(fn (string $label, string $key) => [$key => $label])
->all();
return array_merge($base, $fromConfig);
}
}