67 lines
1.3 KiB
PHP
67 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Fields;
|
|
|
|
use Faker\Generator;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class CheckboxesField extends Field
|
|
{
|
|
/** @var array<int, string> */
|
|
public array $options;
|
|
|
|
public static function name(): string
|
|
{
|
|
return 'Checkboxes';
|
|
}
|
|
|
|
public static function meta(): array
|
|
{
|
|
return [
|
|
['key' => 'options', 'default' => [], 'rules' => ['options' => 'array', 'options.*' => 'required|string'], 'label' => 'Optionen'],
|
|
];
|
|
}
|
|
|
|
public static function default()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public static function fake(Generator $faker): array
|
|
{
|
|
return [
|
|
'options' => $faker->words(4),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getRegistrationRules(): array
|
|
{
|
|
return [
|
|
$this->key => 'array',
|
|
$this->key . '.*' => ['string', Rule::in($this->options)],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getRegistrationAttributes(): array
|
|
{
|
|
return [
|
|
...collect($this->options)->mapWithKeys(fn ($option, $key) => [$this->key . '.' . $key => $this->name])->toArray(),
|
|
$this->key => $this->name,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getRegistrationMessages(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|