adrema/app/Form/Fields/TextField.php

60 lines
1.1 KiB
PHP
Raw Normal View History

2023-12-26 00:44:49 +01:00
<?php
namespace App\Form\Fields;
2023-12-26 20:06:57 +01:00
use Faker\Generator;
2023-12-26 00:44:49 +01:00
class TextField extends Field
{
2024-02-06 01:45:25 +01:00
public bool $required;
2023-12-26 00:44:49 +01:00
public static function name(): string
{
return 'Text';
}
public static function meta(): array
{
2023-12-26 20:06:57 +01:00
return [
['key' => 'required', 'default' => false, 'rules' => ['required' => 'present|boolean'], 'label' => 'Erforderlich'],
];
2023-12-26 00:44:49 +01:00
}
public static function default(): string
{
return '';
}
2023-12-26 20:06:57 +01:00
public static function fake(Generator $faker): array
{
2023-12-27 00:42:31 +01:00
return [
'required' => $faker->boolean(),
];
2023-12-26 20:06:57 +01:00
}
2024-02-06 01:45:25 +01:00
/**
* @inheritdoc
*/
public function getRegistrationRules(): array
{
return [$this->key => $this->required ? ['required', 'string'] : ['nullable', 'string']];
}
/**
* @inheritdoc
*/
public function getRegistrationAttributes(): array
{
return [$this->key => $this->name];
}
/**
* @inheritdoc
*/
public function getRegistrationMessages(): array
{
return [];
}
2023-12-26 00:44:49 +01:00
}