src/Form/ProjectSuperType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use Vich\UploaderBundle\Form\Type\VichFileType;
  10. use App\Entity\Level;
  11. use App\Entity\Project;
  12. /**
  13.  *
  14.  * @author wendell.zheng <wxzheng@ustc.edu.cn>
  15.  */
  16. class ProjectSuperType extends AbstractType
  17. {
  18.     protected $router;
  19.     public function __construct(UrlGeneratorInterface $router)
  20.     {
  21.         $this->router $router;
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options)
  24.     {
  25.         $project $builder->getData();
  26.         $builder->add('batch'null, [
  27.             'label' => '批次',
  28.             'disabled' => true
  29.         ])
  30.             ->add('name'TextType::class, [
  31.             'label' => '名称',
  32.         ])
  33.             ->add('doc'VichFileType::class, [
  34.             'label' => '申请书',
  35.             'download_uri' => $this->router->generate('super_project_download', [
  36.                 'id' => $project->getId()
  37.             ]),
  38.             'download_label' => '下载申请书',
  39.             'allow_delete' => false,
  40.             'required' => false
  41.         ])
  42.             ->add('collegeDoc'VichFileType::class, [
  43.             'label' => '申请书(已填写学院推荐意见)',
  44.             'download_uri' => $this->router->generate('super_project_college_download', [
  45.                 'id' => $project->getId()
  46.             ]),
  47.                 'download_label' => '下载申请书(已填写学院推荐意见)',
  48.             'allow_delete' => false,
  49.             'required' => false
  50.         ])
  51.             ->add('subject'null, [
  52.             'label' => '所属学科',
  53.             'disabled' => true
  54.         ])
  55.             ->add('college'null, [
  56.             'label' => '所属单位',
  57.             'disabled' => true
  58.         ])
  59.             ->add('collegeSort'null, [
  60.             'label' => '学院排序',
  61.             'disabled' => true
  62.         ])
  63.             ->add('status'ChoiceType::class, [
  64.             'label' => '状态',
  65.             'choices' => array_combine(Project::STATUSESProject::STATUSES)
  66.         ]);
  67.         $levels $project->getCategory()->getLevels();
  68.         if ($levels->count()) {
  69.             $builder->add('level'EntityType::class, [
  70.                 'class' => Level::class,
  71.                 'label' => '级别',
  72.                 'choices' => $levels
  73.             ]);
  74.         }
  75.     }
  76. }