2025-06-19 18:24:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Traits\Filament;
|
|
|
|
|
|
|
|
|
|
use Closure;
|
2025-09-08 13:12:33 -04:00
|
|
|
use Filament\Schemas\Schema;
|
2025-06-19 18:24:25 +02:00
|
|
|
|
|
|
|
|
trait CanModifyForm
|
|
|
|
|
{
|
|
|
|
|
/** @var array<Closure> */
|
|
|
|
|
protected static array $customFormModifications = [];
|
|
|
|
|
|
|
|
|
|
public static function modifyForm(Closure $closure): void
|
|
|
|
|
{
|
|
|
|
|
static::$customFormModifications[] = $closure;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
public static function defaultForm(Schema $schema): Schema
|
2025-06-19 18:24:25 +02:00
|
|
|
{
|
2025-09-08 13:12:33 -04:00
|
|
|
return $schema;
|
2025-06-19 18:24:25 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
public static function form(Schema $schema): Schema
|
2025-06-19 18:24:25 +02:00
|
|
|
{
|
2025-09-08 13:12:33 -04:00
|
|
|
$schema = static::defaultForm($schema);
|
2025-06-19 18:24:25 +02:00
|
|
|
|
|
|
|
|
foreach (static::$customFormModifications as $closure) {
|
2025-09-08 13:12:33 -04:00
|
|
|
$schema = $closure($schema);
|
2025-06-19 18:24:25 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
return $schema;
|
2025-06-19 18:24:25 +02:00
|
|
|
}
|
|
|
|
|
}
|