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,
));
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use JacobJoergensen\LaravelPaper\Attributes\ContentPath;
use JacobJoergensen\LaravelPaper\Attributes\Driver;
use JacobJoergensen\LaravelPaper\Paper;
// A question and its answer (markdown body), listed by an FAQ section.
// Default-locale entries, like StoicPage; Stoic::localizedRelation() layers
// the current locale's fields on top.
#[Driver("markdown")]
#[ContentPath("resources/stoic/content/el/faqs")]
class StoicFaq extends Model
{
use Paper;
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use JacobJoergensen\LaravelPaper\Attributes\ContentPath;
use JacobJoergensen\LaravelPaper\Attributes\Driver;
use JacobJoergensen\LaravelPaper\Paper;
// A titled group of FAQs on the FAQ page, ordered by its faqs relation.
// Default-locale entries, like StoicPage; Stoic::localizedRelation() layers
// the current locale's fields on top.
#[Driver("markdown")]
#[ContentPath("resources/stoic/content/el/faq-sections")]
class StoicFaqSection extends Model
{
use Paper;
}
+16
View File
@@ -179,6 +179,22 @@ public static function hasMany(
));
}
// hasMany() with each entry's current-locale fields layered on top (see
// localeOverrides). $folder is both the relation prefix and the content
// folder, e.g. "faqs". Refs pointing at deleted entries are dropped.
public static function localizedRelation(
string $relation,
?array $slugs,
string $folder,
) {
return static::hasMany($relation, $slugs ?? [], $folder)
->filter()
->map(fn($entry) => $entry->forceFill(
static::localeOverrides("{$folder}/{$entry->slug}.md"),
))
->values();
}
public static function hasOne(
string $relation,
string $slug,
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Support;
use Modules\Core\Store\Services\StoreDetailsService;
/**
* {placeholder} => StoreDetails column, usable in Stoic markdown (legal pages,
* FAQ answers).
*/
class StorePlaceholders
{
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,
) {}
/**
* 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.
*/
public function fill(string $content): string
{
$details = $this->storeDetails->current();
return strtr($content, array_map(
fn (string $column) => e((string) ($details->translate($column) ?? '')),
self::PLACEHOLDERS,
));
}
}