Skip to content

Commit b0fc786

Browse files
committed
Replace a common talk form template with a component
Similar to InterviewInputsFactory, TalkInputsFactory is not using a generated factory/interface because I couldn't get it working with the name service that should be passed to TalkInputs, was getting "Service '' is not defined." because of some mapping applied strangely when only one create() parameter was present probably.
1 parent 858e379 commit b0fc786

File tree

8 files changed

+89
-31
lines changed

8 files changed

+89
-31
lines changed

site/app/Admin/Presenters/TalksPresenter.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use MichalSpacekCz\Form\TalkFormFactory;
76
use MichalSpacekCz\Form\TalkSlidesFormFactory;
87
use MichalSpacekCz\Http\HttpInput;
98
use MichalSpacekCz\Media\Exceptions\ContentTypeException;
10-
use MichalSpacekCz\Media\VideoThumbnails;
119
use MichalSpacekCz\Talks\Exceptions\TalkDoesNotExistException;
1210
use MichalSpacekCz\Talks\Talk;
11+
use MichalSpacekCz\Talks\TalkInputs;
12+
use MichalSpacekCz\Talks\TalkInputsFactory;
1313
use MichalSpacekCz\Talks\Talks;
1414
use MichalSpacekCz\Talks\TalkSlides;
1515
use Nette\Application\BadRequestException;
@@ -33,9 +33,8 @@ class TalksPresenter extends BasePresenter
3333
public function __construct(
3434
private readonly Talks $talks,
3535
private readonly TalkSlides $talkSlides,
36-
private readonly TalkFormFactory $talkFormFactory,
36+
private readonly TalkInputsFactory $talkInputsFactory,
3737
private readonly TalkSlidesFormFactory $talkSlidesFormFactory,
38-
private readonly VideoThumbnails $videoThumbnails,
3938
private readonly HttpInput $httpInput,
4039
) {
4140
parent::__construct();
@@ -47,8 +46,6 @@ public function renderDefault(): void
4746
$this->template->pageTitle = $this->translator->translate('messages.title.talks');
4847
$this->template->upcomingTalks = $this->talks->getUpcoming();
4948
$this->template->talks = $this->talks->getAll();
50-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
51-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
5249
}
5350

5451

@@ -62,8 +59,6 @@ public function actionTalk(string $param): void
6259

6360
$this->template->pageTitle = $this->talks->pageTitle('messages.title.talk', $this->talk);
6461
$this->template->talk = $this->talk;
65-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
66-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
6762
}
6863

6964

@@ -88,26 +83,15 @@ public function actionSlides(string $param): void
8883
}
8984

9085

91-
protected function createComponentEditTalk(): Form
86+
protected function createComponentEditTalkInputs(): TalkInputs
9287
{
93-
return $this->talkFormFactory->create(
94-
function (Html $message): never {
95-
$this->flashMessage($message);
96-
$this->redirect('Talks:');
97-
},
98-
$this->talk,
99-
);
88+
return $this->talkInputsFactory->createFor($this->talk);
10089
}
10190

10291

103-
protected function createComponentAddTalk(): Form
92+
protected function createComponentAddTalkInputs(): TalkInputs
10493
{
105-
return $this->talkFormFactory->create(
106-
function (Html $message): never {
107-
$this->flashMessage($message);
108-
$this->redirect('Talks:');
109-
},
110-
);
94+
return $this->talkInputsFactory->create();
11195
}
11296

11397

site/app/Admin/Presenters/templates/Talks/default.latte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div id="pridat-prednasku">
1313
<p><a href="#pridat-prednasku" class="open-container block">Přidat přednášku</a></p>
1414
<div id="pridat-prednasku-container" class="hidden">
15-
{include "common/talkForm.latte", formName: addTalk, talk: null}
15+
{control addTalkInputs}
1616
</div>
1717
</div>
1818
<hr>

site/app/Admin/Presenters/templates/Talks/talk.latte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
{/define}
66

77
{define #content}
8-
{include "common/talkForm.latte", formName: editTalk}
8+
{control editTalkInputs}
99
{/define}

site/app/Talks/TalkInputs.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace MichalSpacekCz\Talks;
5+
6+
use MichalSpacekCz\Application\UiControl;
7+
use MichalSpacekCz\Form\TalkFormFactory;
8+
use MichalSpacekCz\Media\VideoThumbnails;
9+
use Nette\Forms\Form;
10+
use Nette\Utils\Html;
11+
12+
class TalkInputs extends UiControl
13+
{
14+
15+
public function __construct(
16+
private readonly VideoThumbnails $videoThumbnails,
17+
private readonly TalkFormFactory $talkFormFactory,
18+
private readonly ?Talk $talk,
19+
) {
20+
}
21+
22+
23+
public function render(): void
24+
{
25+
$this->template->talk = $this->talk;
26+
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
27+
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
28+
$this->template->render(__DIR__ . '/talkInputs.latte');
29+
}
30+
31+
32+
protected function createComponentTalk(): Form
33+
{
34+
return $this->talkFormFactory->create(
35+
function (Html $message): never {
36+
$this->flashMessage($message);
37+
$this->redirect('Talks:');
38+
},
39+
$this->talk,
40+
);
41+
}
42+
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace MichalSpacekCz\Talks;
5+
6+
use MichalSpacekCz\Form\TalkFormFactory;
7+
use MichalSpacekCz\Media\VideoThumbnails;
8+
9+
class TalkInputsFactory
10+
{
11+
12+
public function __construct(
13+
private readonly VideoThumbnails $videoThumbnails,
14+
private readonly TalkFormFactory $talkFormFactory,
15+
) {
16+
}
17+
18+
19+
public function create(): TalkInputs
20+
{
21+
return new TalkInputs($this->videoThumbnails, $this->talkFormFactory, null);
22+
}
23+
24+
25+
public function createFor(Talk $talk): TalkInputs
26+
{
27+
return new TalkInputs($this->videoThumbnails, $this->talkFormFactory, $talk);
28+
}
29+
30+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
{varType MichalSpacekCz\Talks\Talk $talk}
1+
{varType MichalSpacekCz\Talks\Talk|null $talk}
22
{varType int $videoThumbnailWidth}
33
{varType int $videoThumbnailHeight}
4-
{form $formName class => "aligned wide"}
4+
{form talk class => "aligned wide"}
55
<table>
66
<tr>
77
<th class="align-top">{label action /}</th><td>{input action}<br><small>nevyplňujte, pokud nechcete samostatnou stránku pro přednášku</small></td>
88
</tr>
99
<tr>
10-
<th n:class="$talk?->getAction() ? align-top">{label title /}</th><td>{input title}<br><small n:if="$talk?->getAction()"><a n:href=":Www:Talks:talk $talk->getAction()">zobrazit přednášku</a></small></td>
10+
<th n:class="$talk?->getAction() ? align-top">{label title /}</th><td>{input title}<br><small n:if="$talk?->getAction()"><a href="{plink :Www:Talks:talk $talk->getAction()}">zobrazit přednášku</a></small></td>
1111
</tr>
1212
<tr>
1313
<th class="align-top">{label description /}</th><td>{input description}</td>
@@ -36,7 +36,7 @@
3636
<tr>
3737
<th>{label videoHref /}</th><td>{input videoHref}</td>
3838
</tr>
39-
{include "../../../../../Media/Thumbnails/videoThumbnailsInputs.latte", video: $talk?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
39+
{include "../Media/Thumbnails/videoThumbnailsInputs.latte", video: $talk?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
4040
<tr class="lighter">
4141
<th class="align-top">{label videoEmbed /}</th><td>{input videoEmbed}<br><small><em>deprecated</em></small></td>
4242
</tr>
@@ -59,7 +59,7 @@
5959
<th>{label supersededBy /}</th><td>{input supersededBy}</td>
6060
</tr>
6161
<tr>
62-
<th>{label publishSlides: /}</th><td>{input publishSlides:} <a n:if="$talk?->getId()" n:href="slides $talk->getId()">Upravit slajdy</a></td>
62+
<th>{label publishSlides: /}</th><td>{input publishSlides:} <a n:if="$talk?->getId()" href="{plink slides $talk->getId()}">Upravit slajdy</a></td>
6363
</tr>
6464
<tr>
6565
<th></th><td class="short"><p>{input submit}</p></td>

site/config/presenters.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
- MichalSpacekCz\Admin\Presenters\PulsePresenter
3838
- MichalSpacekCz\Admin\Presenters\ReviewsPresenter
3939
- MichalSpacekCz\Admin\Presenters\SignPresenter
40-
- MichalSpacekCz\Admin\Presenters\TalksPresenter(videoThumbnails: @talkVideoThumbnails)
40+
- MichalSpacekCz\Admin\Presenters\TalksPresenter
4141
- MichalSpacekCz\Admin\Presenters\TrainingsPresenter
4242
- MichalSpacekCz\Admin\Presenters\UserPresenter
4343

site/config/services.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ services:
8282
- MichalSpacekCz\Pulse\Sites(@database.pulse.context)
8383
- MichalSpacekCz\Tags\Tags
8484
- MichalSpacekCz\Talks\TalkFactory(videoFactory: @talkVideoFactory)
85+
- MichalSpacekCz\Talks\TalkInputsFactory(videoThumbnails: @talkVideoThumbnails)
8586
- MichalSpacekCz\Talks\Talks
8687
- MichalSpacekCz\Talks\TalkSlides
8788
- MichalSpacekCz\Templating\Filters

0 commit comments

Comments
 (0)