Add Boolean presenter for checkbox
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2024-04-12 15:42:43 +02:00
parent 1509efd881
commit 63583b9b25
3 changed files with 26 additions and 1 deletions

View File

@ -62,7 +62,10 @@ class FieldCollection extends Collection
*/
public static function fromRequest(Form $form, array $input): self
{
return $form->getFields()->each(fn ($field) => $field->value = array_key_exists($field->key, $input) ? $input[$field->key] : $field->default());
return $form->getFields()->map(function ($field) use ($input) {
$field->value = array_key_exists($field->key, $input) ? $input[$field->key] : $field->default();
return $field;
});
}
public function find(Field $givenField): ?Field

View File

@ -4,6 +4,8 @@ namespace App\Form\Fields;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Form\Presenters\BooleanPresenter;
use App\Form\Presenters\Presenter;
use Faker\Generator;
use Illuminate\Validation\Rule;
@ -72,4 +74,9 @@ class CheckboxField extends Field
public function afterRegistration(Form $form, Participant $participant, array $input): void
{
}
public function getPresenter(): Presenter
{
return app(BooleanPresenter::class);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Form\Presenters;
class BooleanPresenter extends Presenter
{
/**
* @param mixed $value
*/
public function present($value): string
{
return $value ? 'Ja' : 'Nein';
}
}