1: <?php
2:
3: namespace Mapbender\WmcBundle\Form\EventListener;
4:
5: use Mapbender\CoreBundle\Entity\State;
6: use Symfony\Component\Form\Event\DataEvent;
7: use Symfony\Component\Form\FormFactoryInterface;
8: use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9: use Symfony\Component\Form\FormEvents;
10:
11: /**
12: *
13: */
14: class WmcFieldSubscriber implements EventSubscriberInterface
15: {
16:
17: /**
18: * @inheritdoc
19: */
20: public function __construct(FormFactoryInterface $factory)
21: {
22:
23: }
24:
25: /**
26: * @inheritdoc
27: */
28: public static function getSubscribedEvents()
29: {
30: return array(
31: FormEvents::PRE_SET_DATA => 'preSetData',
32: FormEvents::PRE_BIND => 'preBind');
33: }
34:
35: /**
36: * Checkt form fields by PRE_BIND DataEvent
37: *
38: * @param DataEvent $event
39: */
40: public function preBind(DataEvent $event)
41: {
42: $data = $event->getData();
43:
44: if(null === $data)
45: {
46: return;
47: }
48: if(key_exists("state", $data) && strlen($data["state"]) > 0)
49: {
50: $state = new State();
51: $state->setJson(json_decode($data["state"]));
52: $data["state"] = $state;
53: $event->setData($data);
54: }
55: }
56:
57: /**
58: * Checkt form fields by PRE_SET_DATA DataEvent
59: *
60: * @param DataEvent $event
61: */
62: public function preSetData(DataEvent $event)
63: {
64: $data = $event->getData();
65: if(null === $data)
66: {
67: return;
68: }
69: }
70:
71: }