src/Form/System/DOAAttribute.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form\System;
  3. use App\Util\GenericForm;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. /**
  10.  * Used to represent Doctrine ORM Annotation Attribute
  11.  * https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/annotations-reference.html#column
  12.  * https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/annotations-reference.html#column
  13.  */
  14. class DOAAttribute extends GenericForm
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options)
  17.     {
  18.         $options["fields"] = [
  19.             "type" => [
  20.                 "attr" => ["class" => "form-select"],
  21.                 "choices" => [
  22.                     "choices.types.entity" => "entity",
  23.                     "choices.types.integerTypes" => [
  24.                         "choices.types.smallint" => "smallint",
  25.                         "choices.types.integer" => "integer",
  26.                         "choices.types.bigint" => "bigint"
  27.                     ],
  28.                     "choices.types.decimalTypes" => [
  29.                         "choices.types.decimal" => "decimal",
  30.                         "choices.types.float" => "float"
  31.                     ],
  32.                     "choices.types.stringTypes" => [
  33.                         "choices.types.string" => "string",
  34.                         "choices.types.text" => "text"
  35.                     ],
  36.                     "choices.types.dateTimeTypes" => [
  37.                         "choices.types.date" => "date",
  38.                         "choices.types.datetime" => "datetime",
  39.                         "choices.types.time" => "time"
  40.                     ],
  41.                 ],
  42.                 "type" => ChoiceType::class
  43.             ],
  44.             "id" => [
  45.                 "attr" => ["class" => "form-check-custom"],
  46.                 "type" => CheckboxType::class
  47.             ],
  48.             "name" => [
  49.                 "type" => TextType::class
  50.             ],
  51.             "length" => [
  52.                 "attr" => ["class" => "form-control""placeholder" => "label.length"],
  53.                 "html5" => true,
  54.                 "type" => NumberType::class
  55.             ],
  56.             "precision" => [
  57.                 "attr" => ["class" => "form-control""placeholder" => "label.precision"],
  58.                 "html5" => true,
  59.                 "type" => NumberType::class
  60.             ],
  61.             "scale" => [
  62.                 "attr" => ["class" => "form-control""placeholder" => "label.scale"],
  63.                 "html5" => true,
  64.                 "type" => NumberType::class
  65.             ],
  66.             "unique" => [
  67.                 "attr" => ["class" => "form-control""placeholder" => "label.unique.constraint.sort"],
  68.                 "type" => TextType::class
  69.             ],
  70.             "nullable" => [
  71.                 "attr" => ["class" => "form-check-input"],
  72.                 "type" => CheckboxType::class
  73.             ],
  74.             "insertable" => [
  75.                 "attr" => ["class" => "form-check-input"],
  76.                 "type" => CheckboxType::class
  77.             ],
  78.             "updatable" => [
  79.                 "attr" => ["class" => "form-check-input"],
  80.                 "type" => CheckboxType::class
  81.             ],
  82.             "generated" => [
  83.                 "attr" => ["class" => "form-check-input"],
  84.                 "type" => CheckboxType::class
  85.             ],
  86.             "options" => [
  87.                 "attr" => ["class" => "container"],
  88.                 "type" => DOAOptions::class
  89.             ],
  90.             "columnDefinition" => [
  91.                 "type" => TextType::class
  92.             ],
  93.             "externalAlias" => [
  94.                 "type" => TextType::class
  95.             ],
  96.             "order" => [
  97.                 "attr" => ["hidden" => true],
  98.                 "html5" => true,
  99.                 "type" => NumberType::class
  100.             ]
  101.         ];
  102.         foreach (array_keys($options["fields"]) as $attr) {
  103.             $options["fields"][$attr]["label"] = false;
  104.             $options["fields"][$attr]["required"] = $attr == "type";
  105.         }
  106.         parent::buildForm($builder$options);
  107.     }
  108. }