Browse Source

Show slug in article editor

imwald
Nuša Pukšič 3 months ago
parent
commit
9c312aec99
  1. 11
      src/Factory/ArticleFactory.php
  2. 7
      src/Form/EditorType.php
  3. 2
      templates/pages/editor.html.twig

11
src/Factory/ArticleFactory.php

@ -6,20 +6,21 @@ use App\Entity\Article; @@ -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');
}

7
src/Form/EditorType.php

@ -20,8 +20,13 @@ class EditorType extends AbstractType @@ -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,

2
templates/pages/editor.html.twig

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
<div data-nostr-publish-target="status"></div>
{{ form_start(form) }}
{{ form_row(form.slug) }}
{{ form_row(form.title) }}
{{ form_row(form.summary) }}
{{ form_row(form.content) }}

Loading…
Cancel
Save