presubmitChecks() der vier Editoren in ProvidesPressReleasePresubmitChecks zentralisiert (war 4x dupliziert mit Drift). Kanonische Version uebernimmt die bessere Customer-Variante: Firmenname statt leerer Hinweis in der company-Zeile. Dafuer erhalten die Admin-Editoren ein selectedCompany() (Company::withoutGlobalScopes find), das auch in with() genutzt wird; Customer behaelt seine user-gescopte Aufloesung via CustomerCompanyContext. Tests: volle Suite gruen (794 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2.8 KiB
PHP
72 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Concerns;
|
|
|
|
use App\Services\PressRelease\PressReleaseHtmlSanitizer;
|
|
use Livewire\Attributes\Computed;
|
|
|
|
/**
|
|
* Kanonische Pre-Submit-Checkliste der PM-Editoren (Admin + Customer).
|
|
*
|
|
* Vorher in allen vier Editoren dupliziert und leicht auseinandergedriftet
|
|
* (Firmenname vs. leer, trans_choice vs. statischer Text). Diese Version ist
|
|
* die Single Source of Truth.
|
|
*
|
|
* Die nutzende Komponente muss bereitstellen: die Properties `$title`,
|
|
* `$text`, `$companyId`, `$categoryId`, `$contactId`, die Tag-Helfer aus
|
|
* [[InteractsWithPressReleaseTags]] (`tagsArray()`) sowie `selectedCompany()`.
|
|
*/
|
|
trait ProvidesPressReleasePresubmitChecks
|
|
{
|
|
/**
|
|
* @return array<int, array{key: string, status: string, label: string, sub: string}>
|
|
*/
|
|
#[Computed]
|
|
public function presubmitChecks(): array
|
|
{
|
|
$titleLen = mb_strlen(trim($this->title));
|
|
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
|
$tagsCount = count($this->tagsArray());
|
|
|
|
return [
|
|
[
|
|
'key' => 'title',
|
|
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
|
'label' => __('Titel vorhanden'),
|
|
'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'),
|
|
],
|
|
[
|
|
'key' => 'text',
|
|
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
|
'label' => __('Mindestlänge Fließtext erreicht'),
|
|
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
|
],
|
|
[
|
|
'key' => 'company',
|
|
'status' => $this->companyId ? 'ok' : 'err',
|
|
'label' => __('Firma zugeordnet'),
|
|
'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'),
|
|
],
|
|
[
|
|
'key' => 'category',
|
|
'status' => $this->categoryId ? 'ok' : 'err',
|
|
'label' => __('Kategorie gewählt'),
|
|
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
|
],
|
|
[
|
|
'key' => 'contact',
|
|
'status' => $this->contactId ? 'ok' : 'warn',
|
|
'label' => __('Pressekontakt zugeordnet'),
|
|
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
|
],
|
|
[
|
|
'key' => 'tags',
|
|
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
|
'label' => __('Themen-Tags vergeben'),
|
|
'sub' => $tagsCount >= 1
|
|
? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount])
|
|
: __('empfohlen für SEO & Auffindbarkeit'),
|
|
],
|
|
];
|
|
}
|
|
}
|