Files
lucent-laravel/src/Schema/Ui/Text.php
T

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Text implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
2026-05-07 17:42:46 +03:00
public bool $required = false,
public bool $nullable = false,
public ?int $min = null,
public ?int $max = null,
2023-10-21 19:40:24 +03:00
public string $help = "",
2023-10-02 23:10:49 +03:00
public string $default = "",
2026-05-07 17:42:46 +03:00
public bool $readonly = false,
2023-10-02 23:10:49 +03:00
public string $optionsFrom = "",
public string $optionsField = "",
2026-05-07 17:42:46 +03:00
public bool $optionsSuggest = false,
2023-10-06 18:47:50 +03:00
public ?array $selectOptions = null,
2023-10-02 23:10:49 +03:00
public string $group = "",
2026-05-07 17:42:46 +03:00
) {
2023-10-02 23:10:49 +03:00
$this->info = new FieldInfo("text", "Text", FieldType::STRING);
}
public function format(array $input, array $output): array
{
2026-05-07 17:42:46 +03:00
$value = !empty($input[$this->name])
? (string) $input[$this->name]
: null;
$output[$this->name] = Nullable::make(
$this->nullable,
$value,
"",
)->value();
2023-10-02 23:10:49 +03:00
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}