2024-07-10 16:10:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kirby\Form\Mixin;
|
|
|
|
|
|
|
|
|
|
trait Min
|
|
|
|
|
{
|
|
|
|
|
protected int|null $min;
|
|
|
|
|
|
|
|
|
|
public function min(): int|null
|
|
|
|
|
{
|
2025-09-10 14:28:38 +02:00
|
|
|
// set min to at least 1, if required
|
|
|
|
|
if ($this->required === true) {
|
|
|
|
|
return $this->min ?? 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 16:10:33 +02:00
|
|
|
return $this->min;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 17:11:37 +01:00
|
|
|
protected function setMin(int|null $min = null)
|
2024-07-10 16:10:33 +02:00
|
|
|
{
|
|
|
|
|
$this->min = $min;
|
|
|
|
|
}
|
2025-09-10 14:28:38 +02:00
|
|
|
|
|
|
|
|
public function isRequired(): bool
|
|
|
|
|
{
|
|
|
|
|
// set required to true if min is set
|
|
|
|
|
if ($this->min) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->required;
|
|
|
|
|
}
|
2024-07-10 16:10:33 +02:00
|
|
|
}
|