|
@@ -0,0 +1,71 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace MapBundle\EventListener;
|
|
|
+
|
|
|
+use MapBundle\Entity\Interfaces\LocationInterface;
|
|
|
+use MapBundle\Form\Type\LocationType;
|
|
|
+use Sonata\AdminBundle\Event\ConfigureEvent;
|
|
|
+
|
|
|
+class LocationListener
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ConfigureEvent $event
|
|
|
+ */
|
|
|
+ public function configureFormFields(ConfigureEvent $event)
|
|
|
+ {
|
|
|
+ $mapper = $event->getMapper();
|
|
|
+ $subject = $mapper->getAdmin()->getSubject();
|
|
|
+ if ($subject && $subject instanceof LocationInterface) {
|
|
|
+ if ($mapper->hasOpenTab()) {
|
|
|
+ $mapper
|
|
|
+ ->end()
|
|
|
+ ->end();
|
|
|
+ }
|
|
|
+ $options = array(
|
|
|
+ 'translation_domain' => 'MapBundle'
|
|
|
+ );
|
|
|
+ $mapper
|
|
|
+ ->tab('Map', $options)
|
|
|
+ ->with('Location', $options)
|
|
|
+ ->add('location', LocationType::class, array(
|
|
|
+ 'label' => false,
|
|
|
+ ))
|
|
|
+ ->end()
|
|
|
+ ->end()
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ConfigureEvent $event
|
|
|
+ */
|
|
|
+ public function configureShowFields(ConfigureEvent $event)
|
|
|
+ {
|
|
|
+ $mapper = $event->getMapper();
|
|
|
+ $subject = $mapper->getAdmin()->getSubject();
|
|
|
+ if ($subject && $subject instanceof LocationInterface) {
|
|
|
+ if ($mapper->hasOpenTab()) {
|
|
|
+ $mapper
|
|
|
+ ->end();
|
|
|
+ }
|
|
|
+ $options = array(
|
|
|
+ 'translation_domain' => 'MapBundle',
|
|
|
+ 'class' => 'tab-map'
|
|
|
+ );
|
|
|
+ if (!$mapper->has('location')) {
|
|
|
+ $mapper
|
|
|
+ ->tab('Map', $options)
|
|
|
+ ->with('Location', $options)
|
|
|
+ ->add('location', null, array(
|
|
|
+ 'template' => 'LeafletBundle:CRUD:map_show_field.html.twig',
|
|
|
+ 'translation_domain' => 'MapBundle',
|
|
|
+ ))
|
|
|
+ ->end()
|
|
|
+ ->end()
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|