src/Form/CarSubmitFormType.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. declare(strict_types=1);
  15. /**
  16.  * Pimcore
  17.  *
  18.  * This source file is available under two different licenses:
  19.  * - GNU General Public License version 3 (GPLv3)
  20.  * - Pimcore Enterprise License (PEL)
  21.  * Full copyright and license information is available in
  22.  * LICENSE.md which is distributed with this source code.
  23.  *
  24.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  25.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  26.  */
  27. namespace App\Form;
  28. use Pimcore\Model\DataObject\BodyStyle;
  29. use Pimcore\Model\DataObject\Manufacturer;
  30. use Symfony\Component\Form\AbstractType;
  31. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  32. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  33. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  34. use Symfony\Component\Form\Extension\Core\Type\TextType;
  35. use Symfony\Component\Form\FormBuilderInterface;
  36. class CarSubmitFormType extends AbstractType
  37. {
  38.     /**
  39.      * @inheritDoc
  40.      */
  41.     public function buildForm(FormBuilderInterface $builder, array $options)
  42.     {
  43.         $manufacturers = new Manufacturer\Listing();
  44.         $manufacturerChoices = [];
  45.         foreach ($manufacturers as $manufacturer) {
  46.             $manufacturerChoices[$manufacturer->getName()] = $manufacturer->getId();
  47.         }
  48.         ksort($manufacturerChoices);
  49.         $bodyStyles = new BodyStyle\Listing();
  50.         $bodyStyleChoices = [];
  51.         foreach ($bodyStyles as $bodyStyle) {
  52.             $bodyStyleChoices[$bodyStyle->getName()] = $bodyStyle->getId();
  53.         }
  54.         ksort($bodyStyleChoices);
  55.         $builder
  56.             ->add('name'TextType::class, [
  57.                 'label' => 'general.name',
  58.                 'required' => true
  59.             ])
  60.             ->add('description'TextareaType::class, [
  61.                 'label' => 'general.description',
  62.                 'required' => false
  63.             ])
  64.             ->add('manufacturer'ChoiceType::class, [
  65.                 'label' => 'general.manufacturer',
  66.                 'required' => true,
  67.                 'choices' => $manufacturerChoices
  68.             ])
  69.             ->add('bodyStyle'ChoiceType::class, [
  70.                 'label' => 'general.body-style',
  71.                 'required' => true,
  72.                 'choices' => $bodyStyleChoices
  73.             ])
  74.             ->add('carClass'ChoiceType::class, [
  75.                 'label' => 'general.car-class',
  76.                 'required' => true,
  77.                 'choices' => [
  78.                     'Full-size luxury car' => 'Full-size luxury car',
  79.                     'Grand tourer' => 'Grand tourer',
  80.                     'Light commercial vehicle' => 'Light commercial vehicle',
  81.                     'Muscle Car' => 'Muscle Car',
  82.                     'City Car' => 'City Car',
  83.                     'Executive car' => 'Executive car',
  84.                     'Economy car' => 'Economy car',
  85.                     'Personal luxury car' => 'Personal luxury car',
  86.                     'Full-Size' => 'Full-Size',
  87.                     'Family car' => 'Family car',
  88.                     'Mid-size luxury' => 'Mid-size luxury',
  89.                     'sports car' => 'sports car'
  90.                 ]
  91.             ]);
  92.         $builder
  93.             ->add('_submit'SubmitType::class, [
  94.                 'label' => 'general.submit',
  95.                 'attr' => [
  96.                     'class' => 'btn btn-block btn-success'
  97.                 ]
  98.             ]);
  99.     }
  100. }