2021-09-10 16:02:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
use ViewComponents\Component;
|
|
|
|
|
|
|
|
class FormComponent extends Component
|
|
|
|
{
|
|
|
|
protected ?string $id = null;
|
|
|
|
|
|
|
|
protected string $name = '';
|
|
|
|
|
|
|
|
protected string $value = '';
|
|
|
|
|
|
|
|
protected bool $required = false;
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
protected bool $readonly = false;
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
public function __construct($attributes)
|
|
|
|
{
|
|
|
|
parent::__construct($attributes);
|
|
|
|
|
|
|
|
if ($this->id === null) {
|
|
|
|
$this->id = $this->name;
|
2021-09-15 15:58:21 +00:00
|
|
|
$this->attributes['id'] = $this->id;
|
2021-09-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRequired(string $value): void
|
|
|
|
{
|
|
|
|
$this->required = $value === 'true';
|
2021-09-15 15:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setReadonly(string $value): void
|
|
|
|
{
|
|
|
|
$this->readonly = $value === 'true';
|
|
|
|
if ($this->readonly) {
|
|
|
|
$this->attributes['readonly'] = 'readonly';
|
|
|
|
} else {
|
|
|
|
unset($this->attributes['readonly']);
|
|
|
|
}
|
2021-09-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|