<?php
namespace App\Form\System;
use App\Util\GenericForm;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Used to represent Doctrine ORM Annotation Attribute Options
* https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/annotations-reference.html#column
* https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/annotations-reference.html#column
*/
class DOAOptions extends GenericForm
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$options["fields"] = [
"default" => [
"attr" => ["class" => "form-control"],
"label_format" => "label.defaultValue",
"type" => TextType::class
],
"unsigned" => [
"attr" => ["class" => "form-check-custom"],
"label_attr" => ["class" => "form-control"],
"type" => CheckboxType::class
],
"fixed" => [
"attr" => ["class" => "form-check-custom"],
"label_attr" => ["class" => "form-control"],
"type" => CheckboxType::class
],
"comment" => [
"attr" => ["class" => "form-control"],
"type" => TextType::class
],
"collation" => [
"attr" => ["class" => "form-control"],
"type" => TextType::class
],
"check" => [
"attr" => ["class" => "form-control"],
"type" => TextType::class
]
];
foreach (array_keys($options["fields"]) as $opt) {
$options["fields"][$opt]["required"] = false;
}
$options["attr"] = ["class" => "container"];
parent::buildForm($builder, $options);
$parser = function ($view) {
if (is_numeric($view)) {
$result = (str_contains($view, ".")) ? (float) $view : (int) $view;
} else {
$result = $view;
}
return $result;
};
$builder->get("default")->addModelTransformer(new CallbackTransformer(fn($model) => $model, $parser));
}
}