diff --git a/.gitignore b/.gitignore index d2e292e4..a901b688 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ Tests/Application/.env.test.local # php-cs-fixer .php-cs-fixer.cache php-cs-fixer + +.php-version diff --git a/Controller/WebsiteCommentController.php b/Controller/WebsiteCommentController.php index 64542016..f3c4794e 100644 --- a/Controller/WebsiteCommentController.php +++ b/Controller/WebsiteCommentController.php @@ -127,7 +127,7 @@ public function cgetCommentsAction(string $threadId, Request $request): Response $limit = $request->query->getInt('limit', 10); $offset = $request->query->getInt('offset', 0); - /** @var null|int $pageSize */ + /** @var int|null $pageSize */ $pageSize = $request->get('pageSize'); if ($pageSize) { @trigger_deprecation('sulu/comment-bundle', '2.x', 'The usage of the "pageSize" parameter is deprecated. @@ -170,6 +170,7 @@ public function cgetCommentsAction(string $threadId, Request $request): Response 'data_class' => $this->commentClass, 'threadId' => $threadId, 'referrer' => $referrer, + 'threadTitle' => $request->query->get('threadTitle'), ] ); @@ -245,7 +246,7 @@ public function postCommentsAction(string $threadId, Request $request): Response /** @var CommentInterface $comment */ $comment = $this->commentRepository->createNew(); - /** @var null|int $parent */ + /** @var int|null $parent */ $parent = $request->get('parent'); if ($parent) { $comment->setParent($this->commentRepository->findCommentById($parent)); @@ -270,7 +271,7 @@ public function postCommentsAction(string $threadId, Request $request): Response $comment = $form->getData(); /** @var string $threadTitle */ - $threadTitle = $request->get('threadTitle'); + $threadTitle = $request->request->get('threadTitle', ''); $this->commentManager->addComment($type, $entityId, $comment, $threadTitle); $this->entityManager->flush(); @@ -330,7 +331,7 @@ public function putCommentAction(string $threadId, string $commentId, Request $r public function deleteCommentAction(string $threadId, string $commentId, Request $request): Response { /** @var Comment $comment */ - $comment = $this->commentRepository->findCommentById(\intval($commentId)); + $comment = $this->commentRepository->findCommentById((int) $commentId); $this->entityManager->remove($comment); $this->entityManager->flush(); @@ -347,8 +348,8 @@ public function deleteCommentAction(string $threadId, string $commentId, Request } /** - * @param null|mixed $data - * @param null|string $statusCode + * @param mixed|null $data + * @param string|null $statusCode * @param mixed[] $headers * * @return View diff --git a/Entity/CommentRepository.php b/Entity/CommentRepository.php index 5af91a15..6ef20057 100644 --- a/Entity/CommentRepository.php +++ b/Entity/CommentRepository.php @@ -14,6 +14,9 @@ use Doctrine\ORM\NoResultException; use Gedmo\Tree\Entity\Repository\NestedTreeRepository; +/** + * @extends NestedTreeRepository + */ class CommentRepository extends NestedTreeRepository implements CommentRepositoryInterface { public function findComments(string $type, string $entityId, int $limit = 10, int $offset = 0): array diff --git a/Form/Type/CommentType.php b/Form/Type/CommentType.php index a54d9faa..43681d6c 100644 --- a/Form/Type/CommentType.php +++ b/Form/Type/CommentType.php @@ -43,13 +43,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->setAction($this->router->generate('sulu_comment.post_thread_comments', $attributes)); $builder->add('message', TextareaType::class); - $builder->add('threadTitle', HiddenType::class, ['mapped' => false]); + $builder->add('threadTitle', HiddenType::class, ['mapped' => false, 'data' => $options['threadTitle']]); $builder->add('submit', SubmitType::class); } public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('threadId'); + $resolver->setDefault('threadTitle', ''); $resolver->setDefault('referrer', null); $resolver->setDefault('parent', null); $resolver->setDefault('csrf_protection', false); diff --git a/Twig/CommentFormFactoryTwigExtension.php b/Twig/CommentFormFactoryTwigExtension.php index 32538e72..ac2515b9 100644 --- a/Twig/CommentFormFactoryTwigExtension.php +++ b/Twig/CommentFormFactoryTwigExtension.php @@ -42,8 +42,12 @@ public function getFunctions() ]; } - public function createCommentForm(string $threadId, ?string $referrer = null, ?int $parent = null): FormView - { + public function createCommentForm( + string $threadId, + ?string $referrer = null, + ?int $parent = null, + ?string $threadTitle = null + ): FormView { $form = $this->formFactory->create( CommentType::class, null, @@ -52,6 +56,7 @@ public function createCommentForm(string $threadId, ?string $referrer = null, ?i 'threadId' => $threadId, 'referrer' => $referrer, 'parent' => $parent, + 'threadTitle' => $threadTitle, ] );