Skip to content

Commit

Permalink
Fix thread title
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Dec 11, 2023
1 parent 57b3db1 commit 7d44560
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ Tests/Application/.env.test.local
# php-cs-fixer
.php-cs-fixer.cache
php-cs-fixer

.php-version
13 changes: 7 additions & 6 deletions Controller/WebsiteCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'),
]
);

Expand Down Expand Up @@ -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));
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Entity/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Doctrine\ORM\NoResultException;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;

/**
* @extends NestedTreeRepository<CommentInterface>
*/
class CommentRepository extends NestedTreeRepository implements CommentRepositoryInterface
{
public function findComments(string $type, string $entityId, int $limit = 10, int $offset = 0): array
Expand Down
3 changes: 2 additions & 1 deletion Form/Type/CommentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Twig/CommentFormFactoryTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +56,7 @@ public function createCommentForm(string $threadId, ?string $referrer = null, ?i
'threadId' => $threadId,
'referrer' => $referrer,
'parent' => $parent,
'threadTitle' => $threadTitle,
]
);

Expand Down

0 comments on commit 7d44560

Please sign in to comment.