diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-01-17 02:11:31 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-01-17 02:11:31 +0900 |
| commit | deacd0dfc195bca41af631114804d29937337cd8 (patch) | |
| tree | f1f83580e5bc892c0794ac41632bc0cce3498f65 /services/app/src/Form/FormBase.php | |
| parent | 38ddeb28ec846ee966d0fe6873585d697a9ef373 (diff) | |
| download | phperkaigi-2024-albatross-deacd0dfc195bca41af631114804d29937337cd8.tar.gz phperkaigi-2024-albatross-deacd0dfc195bca41af631114804d29937337cd8.tar.zst phperkaigi-2024-albatross-deacd0dfc195bca41af631114804d29937337cd8.zip | |
.
Diffstat (limited to 'services/app/src/Form/FormBase.php')
| -rw-r--r-- | services/app/src/Form/FormBase.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/services/app/src/Form/FormBase.php b/services/app/src/Form/FormBase.php new file mode 100644 index 0000000..cc29442 --- /dev/null +++ b/services/app/src/Form/FormBase.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\Albatross\Form; + +abstract class FormBase +{ + public function __construct( + protected readonly FormState $state, + ) { + } + + /** + * @return array{action: ?string, submit_label: string, items: list<FormItem>, state: array<string, string>, errors: array<string, string>} + */ + public function toTemplateVars(): array + { + return [ + 'action' => $this->action(), + 'submit_label' => $this->submitLabel(), + 'items' => $this->items(), + 'state' => $this->state->getParams(), + 'errors' => $this->state->getErrors(), + ]; + } + + abstract public function pageTitle(): string; + + abstract public function redirectUrl(): string; + + protected function action(): ?string + { + return null; + } + + abstract protected function submitLabel(): string; + + /** + * @return list<FormItem> + */ + abstract protected function items(): array; + + /** + * @return array<string, mixed> + */ + public function getRenderContext(): array + { + return []; + } + + abstract public function submit(): void; +} |
