Neues Modul Glossar (0.27.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d148f2fbe2
commit
0bd20a527e
121 changed files with 946 additions and 298 deletions
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Glossar\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Pagebuilder\Field;
|
||||
use App\Support\Audit;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
|
||||
|
||||
class GlossaryController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return Inertia::render('glossar::Index', [
|
||||
'entries' => GlossaryEntry::query()->orderBy('sort_key')->orderBy('term')->get()->map->toPortal(),
|
||||
'canManage' => $request->user()->can('glossary.manage'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry = GlossaryEntry::query()->create([...$this->validated($request), 'created_by' => $request->user()->id, 'updated_by' => $request->user()->id]);
|
||||
Audit::log('glossary.created', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', '„'.$entry->term.'“ ist im Glossar.');
|
||||
}
|
||||
|
||||
public function update(Request $request, GlossaryEntry $entry): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry->update([...$this->validated($request, $entry), 'updated_by' => $request->user()->id]);
|
||||
Audit::log('glossary.updated', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', 'Gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, GlossaryEntry $entry): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry->delete();
|
||||
Audit::log('glossary.deleted', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', '„'.$entry->term.'“ gelöscht.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request, ?GlossaryEntry $entry = null): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'term' => ['required', 'string', 'max:150'],
|
||||
'aliases' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:50000'],
|
||||
'link_url' => ['nullable', 'string', 'max:1000'],
|
||||
'link_label' => ['nullable', 'string', 'max:100'],
|
||||
], [], ['term' => 'Begriff', 'aliases' => 'Abkürzung / Synonyme', 'description' => 'Erklärung', 'link_url' => 'Link']);
|
||||
|
||||
$term = trim($data['term']);
|
||||
$duplicate = GlossaryEntry::query()->where('sort_key', GlossaryEntry::sortKey($term))->when($entry, fn ($q) => $q->whereKeyNot($entry->id))->exists();
|
||||
if ($duplicate) {
|
||||
throw ValidationException::withMessages(['term' => 'Diesen Begriff gibt es schon im Glossar.']);
|
||||
}
|
||||
|
||||
$link = filled($data['link_url'] ?? null) ? Field::safeUrl($data['link_url']) : '';
|
||||
|
||||
return [
|
||||
'term' => $term,
|
||||
'aliases' => filled($data['aliases'] ?? null) ? trim($data['aliases']) : null,
|
||||
'description' => filled($data['description'] ?? null) ? app(RichText::class)->sanitize($data['description']) : null,
|
||||
'link_url' => $link !== '' ? $link : null,
|
||||
'link_label' => $link !== '' && filled($data['link_label'] ?? null) ? trim($data['link_label']) : null,
|
||||
];
|
||||
}
|
||||
|
||||
private function authorizeManage(Request $request): void
|
||||
{
|
||||
abort_unless($request->user()->can('glossary.manage'), 403);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue