diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 3f795d9..90391cb 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,5 +1,6 @@ twig: file_name_pattern: '*.twig' + form_themes: ['form_div_layout.html.twig'] when@test: twig: diff --git a/migrations/Version20240612095513.php b/migrations/Version20240612095513.php new file mode 100644 index 0000000..8127645 --- /dev/null +++ b/migrations/Version20240612095513.php @@ -0,0 +1,31 @@ + '\d+'] )] @@ -66,7 +66,7 @@ class PostController extends AbstractController $this->em->persist($post); $this->em->flush(); - return new Response($user->getUserIdentifier()); + return $this->redirectToRoute('display_post', ['id' => $post->getId()]); } return $this->render('post/new.html.twig', [ diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 26143f4..48975f5 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -7,6 +7,8 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Mapping\ClassMetadata; #[ORM\Entity(repositoryClass: PostRepository::class)] class Post @@ -25,9 +27,6 @@ class Post #[ORM\Column] private ?bool $isDream = null; - // #[ORM\Column()] - // private ?DateTime $dateCreated = null; - #[ORM\Column(options: ["default" => 0])] private int $upVote = 0; @@ -97,18 +96,6 @@ class Post return $this; } - public function getDateCreated(): ?DateTime - { - return $this->dateCreated; - } - - public function setDateCreated(?DateTime $dateCreated): static - { - $this->dateCreated = $dateCreated; - - return $this; - } - public function getUpVote(): ?int { return $this->upVote; @@ -198,4 +185,14 @@ class Post return $this; } + + public static function loadValidatorMetadata(ClassMetadata $metadata): void + { + $metadata->addPropertyConstraint('title', new Assert\Length([ + 'min' => 10, + 'max' => 200, + 'minMessage' => 'Your title must be at least {{ limit }} characters long', + 'maxMessage' => 'Your title cannot be longer than {{ limit }} characters', + ])); + } } diff --git a/src/Form/Type/PostType.php b/src/Form/Type/PostType.php index 3578cea..6ca98ac 100644 --- a/src/Form/Type/PostType.php +++ b/src/Form/Type/PostType.php @@ -4,7 +4,6 @@ namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; -use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -16,12 +15,20 @@ class PostType extends AbstractType { $builder ->add('title', TextType::class) - ->add('text', TextareaType::class) - ->add('dream', CheckboxType::class) + ->add('text', TextareaType::class, [ + 'attr' => ['rows' => '10'], + 'label' => 'Your dream' + ]) + ->add('dream', CheckboxType::class, [ + 'required' => false, + 'label' => 'Was it a nightmare ?' + ]) // ->add('tags', ChoiceType::class, [ // "multiple" => true // ]) - ->add('submit', SubmitType::class) + ->add('submit', SubmitType::class, [ + 'label' => 'Publish' + ]) ; } } diff --git a/templates/base.html.twig b/templates/base.html.twig index 3cda30f..c787378 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -2,13 +2,15 @@
-{{ post.text|u.truncate(150, true, '...') }}