lib/HanabusaBundle/src/Form/EventSubscriber/ChangeWorkCostFieldSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace Kzl\HanabusaBundle\Form\EventSubscriber;
  3. // use Symfony\Component\Form\Event\DataEvent;
  4. use Symfony\Component\Form\FormEvent;
  5. use Symfony\Component\Form\FormFactoryInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Form\FormEvents;
  8. use Kzl\HanabusaBundle\Repository\MstWorkCostRepository;
  9. use Kzl\HanabusaBundle\Repository\ShindanRepository;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. /**
  12.  * 診断入力フォームの作業金額の入力コントロールの動的フォーム作成
  13.  *
  14.  * @author kawaguchi@kuzilla.co.jp
  15.  */
  16. class ChangeWorkCostFieldSubscriber implements EventSubscriberInterface
  17. {
  18.     private $factory;
  19.     public function __construct(FormFactoryInterface $factory) {
  20.         $this->factory $factory;
  21.     }
  22.     public static function getSubscribedEvents() {
  23.         return array(FormEvents::PRE_SET_DATA => 'preSetData');
  24.     }
  25.     public function preSetData(FormEvent $event)
  26.     {
  27.         $data $event->getData();
  28.         $form $event->getForm();
  29.         if(null === $data) {
  30.             return;
  31.         }
  32.         // 作業金額マスタの入力f方法により作成するフォームを変更する
  33.         switch($data->getInputMethod()) {
  34.             case MstWorkCostRepository::INPUT_METHOD_EXIST// 入力方法 有無
  35.                 // 有無
  36.                 $form->add($this->factory->createNamed('exists',ChoiceType::class, $data->isExists(), array(
  37.                      'auto_initialize' => false,
  38.                      'label'=>'裏蓋開閉'
  39.                      'choices' => array_flip(ShindanRepository::getBackCover()), 
  40.                      'expanded'=> true
  41.                      'multiple'=>false
  42.                      'required'=>false
  43.                      'attr'=>array(
  44.                         'class'=>'inline label90 shindan_collection_choices shindan_choices',
  45.                     ), 
  46.                     'label_attr'=>[
  47.                         'class'=>'shindan_collection_choices',
  48.                         'data-iconpos'=>"",
  49.                     ]
  50.                 )));
  51.                 // 金額入力はhidden
  52.                 $form->add($this->factory->createNamed('cost','Symfony\Component\Form\Extension\Core\Type\HiddenType'$data->getCost(), array('auto_initialize' => false,'attr'=>array('data-role'=>''))));
  53.                 break;
  54.             case MstWorkCostRepository::INPUT_METHOD_MONEY// 入力方法 金額
  55.             default:
  56.                 // 2014/5/28 mitsunaga 日本語入力可能
  57.                 // 金額入力
  58.                 $form->add($this->factory->createNamed('cost','Symfony\Component\Form\Extension\Core\Type\TextType'$data->getCost(), array('auto_initialize' => false'label'=>'test''required'=>false'attr' =>array('data-role'=>'none','class'=>'width70p','style'=>'text-align:right;ime-mode:inactive;'/*,'pattern'=>'[0-9]*'*/))));
  59.                 // 有無はhidden
  60.                 $form->add($this->factory->createNamed('exists','Symfony\Component\Form\Extension\Core\Type\HiddenType'$data->isExists(), array('auto_initialize' => false,'attr'=>array('data-role'=>''))));
  61.                 break;
  62.         }
  63.     }
  64. }