From 9c312aec99aa424d52976fbf9c38e095342ed689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Sat, 25 Oct 2025 12:08:09 +0200 Subject: [PATCH] Show slug in article editor --- src/Factory/ArticleFactory.php | 11 ++++++----- src/Form/EditorType.php | 7 ++++++- templates/pages/editor.html.twig | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Factory/ArticleFactory.php b/src/Factory/ArticleFactory.php index c2bd025..0b3ad24 100644 --- a/src/Factory/ArticleFactory.php +++ b/src/Factory/ArticleFactory.php @@ -6,20 +6,21 @@ use App\Entity\Article; use App\Enum\EventStatusEnum; use App\Enum\KindsEnum; use InvalidArgumentException; -use Mdanter\Ecc\Crypto\Signature\SchnorrSignature; +use Mdanter\Ecc\Crypto\Signature\SchnorrSigner; /** - * Map nostr events of kind 30023 to local article entity + * Map nostr events of kind 30023, 30024 to local article entity */ class ArticleFactory { public function createFromLongFormContentEvent($source): Article { - if ($source->kind !== KindsEnum::LONGFORM->value) { - throw new InvalidArgumentException('Source event kind should be 30023'); + if ($source->kind !== KindsEnum::LONGFORM->value || + $source->kind !== KindsEnum::LONGFORM_DRAFT->value) { + throw new InvalidArgumentException('Source event kind should be 30023 or 30024'); } - $validity = (new SchnorrSignature())->verify($source->pubkey, $source->sig, $source->id); + $validity = (new SchnorrSigner())->verify($source->pubkey, $source->sig, $source->id); if (!$validity) { throw new InvalidArgumentException('Invalid event signature'); } diff --git a/src/Form/EditorType.php b/src/Form/EditorType.php index e44b5b8..763d2b6 100644 --- a/src/Form/EditorType.php +++ b/src/Form/EditorType.php @@ -20,8 +20,13 @@ class EditorType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { - // create a form with a title field, a QuillType content field and a submit button $builder + ->add('slug', TextType::class, [ + 'required' => false, + 'help' => 'Leave empty to auto-generate from title. When editing an existing article, changing the slug will fork the article.', + 'sanitize_html' => true, + 'attr' => ['placeholder' => 'awesome-article-slug', 'class' => 'form-control'] + ]) ->add('title', TextType::class, [ 'required' => true, 'sanitize_html' => true, diff --git a/templates/pages/editor.html.twig b/templates/pages/editor.html.twig index 5afc883..46f59c3 100644 --- a/templates/pages/editor.html.twig +++ b/templates/pages/editor.html.twig @@ -28,7 +28,7 @@
{{ form_start(form) }} - + {{ form_row(form.slug) }} {{ form_row(form.title) }} {{ form_row(form.summary) }} {{ form_row(form.content) }}