src/Form/System/DOAOptions.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form\System;
  3. use App\Util\GenericForm;
  4. use Symfony\Component\Form\CallbackTransformer;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. /**
  9.  * Used to represent Doctrine ORM Annotation Attribute Options
  10.  * https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/annotations-reference.html#column
  11.  * https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/annotations-reference.html#column
  12.  */
  13. class DOAOptions extends GenericForm
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $options["fields"] = [
  18.             "default" => [
  19.                 "attr" => ["class" => "form-control"],
  20.                 "label_format" => "label.defaultValue",
  21.                 "type" => TextType::class
  22.             ],
  23.             "unsigned" => [
  24.                 "attr" => ["class" => "form-check-custom"],
  25.                 "label_attr" => ["class" => "form-control"],
  26.                 "type" => CheckboxType::class
  27.             ],
  28.             "fixed" => [
  29.                 "attr" => ["class" => "form-check-custom"],
  30.                 "label_attr" => ["class" => "form-control"],
  31.                 "type" => CheckboxType::class
  32.             ],
  33.             "comment" => [
  34.                 "attr" => ["class" => "form-control"],
  35.                 "type" => TextType::class
  36.             ],
  37.             "collation" => [
  38.                 "attr" => ["class" => "form-control"],
  39.                 "type" => TextType::class
  40.             ],
  41.             "check" => [
  42.                 "attr" => ["class" => "form-control"],
  43.                 "type" => TextType::class
  44.             ]
  45.         ];
  46.         foreach (array_keys($options["fields"]) as $opt) {
  47.             $options["fields"][$opt]["required"] = false;
  48.         }
  49.         $options["attr"] = ["class" => "container"];
  50.         parent::buildForm($builder$options);
  51.         $parser = function ($view) {
  52.             if (is_numeric($view)) {
  53.                 $result = (str_contains($view".")) ? (float) $view : (int) $view;
  54.             } else {
  55.                 $result $view;
  56.             }
  57.             return $result;
  58.         };
  59.         $builder->get("default")->addModelTransformer(new CallbackTransformer(fn($model) => $model$parser));
  60.     }
  61. }