generated from boboko/starter
setup for stoic settings, changes in legal pages to use core's store details and contact page to show contact info next to form
This commit is contained in:
@@ -3,9 +3,26 @@
|
||||
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');
|
||||
@@ -34,6 +51,24 @@ private function show(string $slug)
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return view('legal', ['page' => $page]);
|
||||
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,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user