73 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Form\Fields;
 | |
| 
 | |
| use App\Form\Models\Form;
 | |
| use App\Form\Models\Participant;
 | |
| use Faker\Generator;
 | |
| use Illuminate\Validation\Rule;
 | |
| 
 | |
| class CheckboxField extends Field
 | |
| {
 | |
|     public bool $required;
 | |
|     public string $description;
 | |
| 
 | |
|     public static function name(): string
 | |
|     {
 | |
|         return 'Checkbox';
 | |
|     }
 | |
| 
 | |
|     public static function meta(): array
 | |
|     {
 | |
|         return [
 | |
|             ['key' => 'description', 'default' => '', 'rules' => ['description' => 'required|string'], 'label' => 'Beschreibung'],
 | |
|             ['key' => 'required', 'default' => false, 'rules' => ['required' => 'present|boolean'], 'label' => 'Erforderlich'],
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     public static function default()
 | |
|     {
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
|     public static function fake(Generator $faker): array
 | |
|     {
 | |
|         return [
 | |
|             'description' => $faker->text(),
 | |
|             'required' => $faker->boolean(),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @inheritdoc
 | |
|      */
 | |
|     public function getRegistrationRules(): array
 | |
|     {
 | |
|         return [
 | |
|             $this->key => $this->required ? ['boolean', 'accepted'] : ['present', 'boolean'],
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @inheritdoc
 | |
|      */
 | |
|     public function getRegistrationAttributes(): array
 | |
|     {
 | |
|         return [
 | |
|             $this->key => $this->name,
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @inheritdoc
 | |
|      */
 | |
|     public function getRegistrationMessages(): array
 | |
|     {
 | |
|         return [];
 | |
|     }
 | |
| 
 | |
|     public function afterRegistration(Form $form, Participant $participant, array $input): void
 | |
|     {
 | |
|     }
 | |
| }
 |