This commit is contained in:
elvira committed 2026-10-26 16:06:55 +02:00
1 parent 50ec0eebf2
commit 1e4da2c8cc
73 files changed
+763 -43

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers;
use App\Models\StoicFaq;
use App\Models\StoicFaqSection;
use App\Models\StoicPage;
use App\Services\Stoic;
use App\Support\StorePlaceholders;
use Illuminate\Support\Str;
use Illuminate\View\View;
/**
* FAQ page: pages/faq.md lists the sections, each section lists its FAQs
* (both Stoic relations, so the order is the editor's). Answers are markdown
* and can use the same store placeholders as the legal pages.
*/
class FaqController extends Controller
{
public function index(string $locale, StorePlaceholders $placeholders): View
{
$page = StoicPage::localized('faq');
if (! $page) {
abort(404);
}
$sections = Stoic::localizedRelation(StoicFaqSection::class, $page->sections, 'faq-sections')
->map(function (StoicFaqSection $section) use ($placeholders) {
$section->items = Stoic::localizedRelation(StoicFaq::class, $section->faqs, 'faqs')
->map(fn (StoicFaq $faq) => $faq->forceFill([
'answer' => Str::markdown($placeholders->fill($faq->content ?? '')),
]));
return $section;
})
->filter(fn (StoicFaqSection $section) => $section->items->isNotEmpty())
->values();
return view('faq', [
'page' => $page,
'sections' => $sections,
]);
}
}
+3 -32
View File
@@ -3,26 +3,12 @@
namespace App\Http\Controllers;
use App\Models\StoicPage;
use Modules\Core\Store\Services\StoreDetailsService;
use App\Support\StorePlaceholders;
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_contact_email}' => 'contact_email',
'{store_legal_name}' => 'legal_name',
'{store_tax_identifier}' => 'tax_identifier',
'{store_registration_number}' => 'registration_number',
];
public function __construct(
private readonly StoreDetailsService $storeDetails,
private readonly StorePlaceholders $placeholders,
) {}
public function terms(string $locale)
@@ -55,22 +41,7 @@ private function show(string $slug)
return view('legal', [
'page' => $page,
'content' => $this->fillPlaceholders($page->content ?? ''),
'content' => $this->placeholders->fill($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,
));
}
}