generated from boboko/starter
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\StoicPage;
|
|
use Modules\Core\Store\Services\StoreDetailsService;
|
|
|
|
class LegalPageController extends Controller
|
|
{
|
|
/**
|
|
* {placeholder} => StoreDetails column, usable in the Stoic legal page
|
|
* markdown.
|
|
*/
|
|
private const PLACEHOLDERS = [
|
|
'{store_name}' => 'name',
|
|
'{store_address}' => 'address',
|
|
'{store_phone}' => 'phone',
|
|
'{store_tax_identifier}' => 'tax_identifier',
|
|
'{store_registration_number}' => 'registration_number',
|
|
];
|
|
|
|
public function __construct(
|
|
private readonly StoreDetailsService $storeDetails,
|
|
) {}
|
|
|
|
public function terms(string $locale)
|
|
{
|
|
return $this->show('terms-and-conditions');
|
|
}
|
|
|
|
public function shippingReturns(string $locale)
|
|
{
|
|
return $this->show('shipping-returns');
|
|
}
|
|
|
|
public function privacy(string $locale)
|
|
{
|
|
return $this->show('privacy-policy');
|
|
}
|
|
|
|
public function cookies(string $locale)
|
|
{
|
|
return $this->show('cookies-policy');
|
|
}
|
|
|
|
private function show(string $slug)
|
|
{
|
|
$page = StoicPage::firstWhere('slug', $slug);
|
|
|
|
if (! $page) {
|
|
abort(404);
|
|
}
|
|
|
|
return view('legal', [
|
|
'page' => $page,
|
|
'content' => $this->fillPlaceholders($page->content ?? ''),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Swapped in before the markdown is rendered, so values are escaped: the
|
|
* rendered markdown is printed unescaped. An empty field renders as
|
|
* nothing rather than leaving the raw placeholder on the page.
|
|
*/
|
|
private function fillPlaceholders(string $content): string
|
|
{
|
|
$details = $this->storeDetails->current();
|
|
|
|
return strtr($content, array_map(
|
|
fn (string $column) => e((string) ($details->translate($column) ?? '')),
|
|
self::PLACEHOLDERS,
|
|
));
|
|
}
|
|
}
|