1: <?php
2:
3: namespace Mapbender\CoreBundle\Form\EventListener;
4:
5: use Symfony\Component\Form\Event\DataEvent;
6: use Symfony\Component\Form\FormFactoryInterface;
7: use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8: use Symfony\Component\Form\FormEvents;
9:
10: 11: 12:
13: class MapFieldSubscriber implements EventSubscriberInterface
14: {
15:
16: 17: 18:
19: public function __construct(FormFactoryInterface $factory)
20: {
21:
22: }
23:
24: 25: 26:
27: public static function getSubscribedEvents()
28: {
29: return array(
30: FormEvents::PRE_SET_DATA => 'preSetData',
31: FormEvents::PRE_BIND => 'preBind');
32: }
33:
34: 35: 36: 37: 38:
39: public function preBind(DataEvent $event)
40: {
41: $data = $event->getData();
42:
43: if(null === $data)
44: {
45: return;
46: }
47: if(key_exists("otherSrs", $data) && is_string($data["otherSrs"]))
48: {
49: $data["otherSrs"] = preg_split("/\s?,\s?/", $data["otherSrs"]);
50: $event->setData($data);
51: }
52: if(key_exists("scales", $data) && is_string($data["scales"]))
53: {
54: $data["scales"] = preg_split("/\s?,\s?/", $data["scales"]);
55: $event->setData($data);
56: }
57: }
58:
59: 60: 61: 62: 63:
64: public function preSetData(DataEvent $event)
65: {
66: $data = $event->getData();
67: if(null === $data)
68: {
69: return;
70: }
71:
72: if(key_exists("otherSrs", $data) && is_array($data["otherSrs"]))
73: {
74: $data["otherSrs"] = implode(",", $data["otherSrs"]);
75: $event->setData($data);
76: }
77: if(key_exists("scales", $data) && is_array($data["scales"]))
78: {
79: $data["scales"] = implode(",", $data["scales"]);
80: $event->setData($data);
81: }
82: }
83:
84: }