Skip to content

Commit 60373e8

Browse files
committed
4767: Fixed handling of context for new questions
1 parent af10b59 commit 60373e8

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ See [keep a changelog] for information about writing changes to this log.
88

99
## [Unreleased]
1010

11+
## [3.0.1] - 2025-06-23
12+
13+
* [PR-34](https://github.com/itk-dev/sysstatus/pull/34)
14+
4767: Fixed handling of context for new questions
15+
1116
## [3.0.0] - 2025-06-13
1217

1318
* [PR-33](https://github.com/itk-dev/sysstatus/pull/33)

src/Controller/Admin/AnswerCrudController.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\Answer;
66
use App\Entity\Question;
7+
use App\Entity\Report;
78
use App\Entity\System;
89
use Doctrine\ORM\EntityManagerInterface;
910
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
@@ -59,24 +60,28 @@ protected function getRedirectResponseAfterSave(AdminContext $context, string $a
5960
#[\Override]
6061
public function createEntity(string $entityFqcn): Answer
6162
{
62-
/** @var Answer $entity */
63-
$entity = parent::createEntity($entityFqcn);
64-
65-
// Set system and question on new answers.
63+
// Set question and report OR system on new answers.
6664
$params = $this->getContext()->getRequest()->query->all();
67-
if (isset($params['system'], $params['question'])) {
68-
$system = $this->entityManager->getRepository(System::class)->find($params['system']);
69-
$question = $this->entityManager->getRepository(Question::class)->find($params['question']);
70-
if ($system && $question) {
71-
$entity
72-
->setSystem($system)
73-
->setQuestion($question);
74-
} else {
75-
throw new BadRequestHttpException();
76-
}
65+
// Question is required.
66+
$question = isset($params['question']) ? $this->entityManager->getRepository(Question::class)->find($params['question']) : null;
67+
if (null === $question) {
68+
throw new BadRequestHttpException('Missing or invalid question');
7769
}
70+
// One or report or system is required.
71+
$report = isset($params['report']) ? $this->entityManager->getRepository(Report::class)->find($params['report']) : null;
72+
$system = isset($params['system']) ? $this->entityManager->getRepository(System::class)->find($params['system']) : null;
73+
74+
if (null === $report && null === $system) {
75+
throw new BadRequestHttpException('Either report or system must be set');
76+
}
77+
78+
/** @var Answer $entity */
79+
$entity = parent::createEntity($entityFqcn);
7880

79-
return $entity;
81+
return $entity
82+
->setQuestion($question)
83+
->setReport($report)
84+
->setSystem($system);
8085
}
8186

8287
#[\Override]

templates/easy_admin_overrides/answers_show.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
<td></td>
5151
<td>
5252
<a href="{{ ea_url({
53-
system: entity.instance.id,
53+
report: 'App\\Entity\\Report' == get_class(entity.instance) ? entity.instance.id : null,
54+
system: 'App\\Entity\\System' == get_class(entity.instance) ? entity.instance.id : null,
5455
question: question.id,
5556
referer,
5657
})

0 commit comments

Comments
 (0)