Add Boolean presenter for checkbox
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
1509efd881
commit
63583b9b25
|
@ -62,7 +62,10 @@ class FieldCollection extends Collection
|
||||||
*/
|
*/
|
||||||
public static function fromRequest(Form $form, array $input): self
|
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
|
public function find(Field $givenField): ?Field
|
||||||
|
|
|
@ -4,6 +4,8 @@ namespace App\Form\Fields;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
|
use App\Form\Presenters\BooleanPresenter;
|
||||||
|
use App\Form\Presenters\Presenter;
|
||||||
use Faker\Generator;
|
use Faker\Generator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
@ -72,4 +74,9 @@ class CheckboxField extends Field
|
||||||
public function afterRegistration(Form $form, Participant $participant, array $input): void
|
public function afterRegistration(Form $form, Participant $participant, array $input): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPresenter(): Presenter
|
||||||
|
{
|
||||||
|
return app(BooleanPresenter::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue