<?php
namespace Kzl\HanabusaBundle\Form\EventSubscriber;
// use Symfony\Component\Form\Event\DataEvent;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents;
use Kzl\HanabusaBundle\Repository\MstWorkCostRepository;
use Kzl\HanabusaBundle\Repository\ShindanRepository;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/**
* 診断入力フォームの作業金額の入力コントロールの動的フォーム作成
*
* @author kawaguchi@kuzilla.co.jp
*/
class ChangeWorkCostFieldSubscriber implements EventSubscriberInterface
{
private $factory;
public function __construct(FormFactoryInterface $factory) {
$this->factory = $factory;
}
public static function getSubscribedEvents() {
return array(FormEvents::PRE_SET_DATA => 'preSetData');
}
public function preSetData(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
if(null === $data) {
return;
}
// 作業金額マスタの入力f方法により作成するフォームを変更する
switch($data->getInputMethod()) {
case MstWorkCostRepository::INPUT_METHOD_EXIST: // 入力方法 有無
// 有無
$form->add($this->factory->createNamed('exists',ChoiceType::class, $data->isExists(), array(
'auto_initialize' => false,
'label'=>'裏蓋開閉',
'choices' => array_flip(ShindanRepository::getBackCover()),
'expanded'=> true,
'multiple'=>false,
'required'=>false,
'attr'=>array(
'class'=>'inline label90 shindan_collection_choices shindan_choices',
),
'label_attr'=>[
'class'=>'shindan_collection_choices',
'data-iconpos'=>"",
]
)));
// 金額入力はhidden
$form->add($this->factory->createNamed('cost','Symfony\Component\Form\Extension\Core\Type\HiddenType', $data->getCost(), array('auto_initialize' => false,'attr'=>array('data-role'=>''))));
break;
case MstWorkCostRepository::INPUT_METHOD_MONEY: // 入力方法 金額
default:
// 2014/5/28 mitsunaga 日本語入力可能
// 金額入力
$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]*'*/))));
// 有無はhidden
$form->add($this->factory->createNamed('exists','Symfony\Component\Form\Extension\Core\Type\HiddenType', $data->isExists(), array('auto_initialize' => false,'attr'=>array('data-role'=>''))));
break;
}
}
}