Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • DrupalIntegrationBundle
      • DependencyInjection
      • Security
        • Authentication
          • Provider
          • Token
        • Authorization
          • Voter
        • Factory
        • Firewall
        • User
      • Session
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • EventListener
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • MapFieldSubscriber
  • PrintClientSubscriber
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  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: use Mapbender\CoreBundle\Element\Type\PrintClientTemplateAdminType;
 10: use Mapbender\CoreBundle\Element\Type\PrintClientQualityAdminType;
 11: 
 12: /**
 13:  * 
 14:  */
 15: class PrintClientSubscriber implements EventSubscriberInterface
 16: {
 17: 
 18:     /**
 19:      * A FormFactoryInterface 's Factory
 20:      * 
 21:      * @var \Symfony\Component\Form\FormFactoryInterface 
 22:      */
 23:     private $factory;
 24:     
 25:     /**
 26:      * The application
 27:      * 
 28:      * @var application
 29:      */
 30:     private $application;
 31: 
 32:     /**
 33:      * Creates a subscriber
 34:      * 
 35:      * @param \Symfony\Component\Form\FormFactoryInterface $factory
 36:      */
 37:     public function __construct(FormFactoryInterface $factory, $application)
 38:     {
 39:         $this->factory = $factory;
 40:         $this->application = $application;
 41:     }
 42: 
 43:     /**
 44:      * @inheritdoc
 45:      */
 46:     public static function getSubscribedEvents()
 47:     {
 48:         return array(
 49:             FormEvents::PRE_SET_DATA => 'preSetData',
 50:             FormEvents::PRE_BIND => 'preBind');
 51:     }
 52: 
 53:     /**
 54:      * Checkt form fields by PRE_BIND DataEvent
 55:      * 
 56:      * @param DataEvent $event
 57:      */
 58:     public function preBind(DataEvent $event)
 59:     {
 60:         $data = $event->getData();
 61:         $form = $event->getForm();
 62:         if(null === $data)
 63:         {
 64:             return;
 65:         }
 66:         if(key_exists("scales", $data) && is_string($data["scales"]))
 67:         {
 68:             $data["scales"] = preg_split("/\s?,\s?/", $data["scales"]);
 69:             $event->setData($data);
 70:         }
 71:         
 72:         if(key_exists("templates", $data) )
 73:         {
 74:             $form->add($this->factory->createNamed(
 75:                                 'templates', "collection", null,
 76:                                 array(
 77:                             'property_path' => '[templates]',
 78:                             'type' => new PrintClientTemplateAdminType(),
 79:                             'options' => array(
 80:                                 ))));
 81:         }
 82:         if(key_exists("quality_levels", $data) )
 83:         {
 84:             $form->add($this->factory->createNamed(
 85:                                 'quality_levels', "collection", null,
 86:                                 array(
 87:                             'property_path' => '[quality_levels]',
 88:                             'type' => new PrintClientQualityAdminType(),
 89:                             'options' => array(
 90:                                 ))));
 91:         }
 92: 
 93:     }
 94: 
 95:     /**
 96:      * Checkt form fields by PRE_SET_DATA DataEvent
 97:      * 
 98:      * @param DataEvent $event
 99:      */
100:     public function preSetData(DataEvent $event)
101:     {
102:         $data = $event->getData();
103:         $form = $event->getForm();
104:         if(null === $data)
105:         {
106:             return;
107:         }
108: 
109:         if(key_exists("scales", $data) && is_array($data["scales"]))
110:         {
111:             $data["scales"] = implode(",", $data["scales"]);
112:             $event->setData($data);
113:         }
114:         
115:         if(key_exists("templates", $data) )
116:         {
117:             $form->add($this->factory->createNamed(
118:                                 'templates', "collection", null,
119:                                 array(
120:                             'property_path' => '[templates]',
121:                             'type' => new PrintClientTemplateAdminType(),
122:                             'options' => array(
123:                                 ))));
124:         }
125:         
126:         if(key_exists("quality_levels", $data) )
127:         {
128:             $form->add($this->factory->createNamed(
129:                                 'quality_levels', "collection", null,
130:                                 array(
131:                             'property_path' => '[quality_levels]',
132:                             'type' => new PrintClientQualityAdminType(),
133:                             'options' => array(
134:                                 ))));
135:         }
136:         
137:     }
138: 
139: }
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0