LocationListener.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace MapBundle\EventListener;
  3. use MapBundle\Entity\Interfaces\LocationInterface;
  4. use MapBundle\Form\Type\LocationType;
  5. use Sonata\AdminBundle\Event\ConfigureEvent;
  6. class LocationListener
  7. {
  8. /**
  9. * @param ConfigureEvent $event
  10. */
  11. public function configureFormFields(ConfigureEvent $event)
  12. {
  13. $mapper = $event->getMapper();
  14. $subject = $mapper->getAdmin()->getSubject();
  15. if ($subject && $subject instanceof LocationInterface) {
  16. if ($mapper->hasOpenTab()) {
  17. $mapper
  18. ->end()
  19. ->end();
  20. }
  21. $options = array(
  22. 'translation_domain' => 'MapBundle'
  23. );
  24. $mapper
  25. ->tab('Map', $options)
  26. ->with('Location', $options)
  27. ->add('location', LocationType::class, array(
  28. 'label' => false,
  29. ))
  30. ->end()
  31. ->end();
  32. }
  33. }
  34. /**
  35. * @param ConfigureEvent $event
  36. */
  37. public function configureShowFields(ConfigureEvent $event)
  38. {
  39. $mapper = $event->getMapper();
  40. $subject = $mapper->getAdmin()->getSubject();
  41. if ($subject && $subject instanceof LocationInterface) {
  42. if ($mapper->hasOpenTab()) {
  43. $mapper
  44. ->end()
  45. ->end();
  46. }
  47. $options = array(
  48. 'translation_domain' => 'MapBundle',
  49. );
  50. if (!$mapper->has('location')) {
  51. $mapper
  52. ->tab('Map', $options)
  53. ->with('Location', $options)
  54. ->add('location', null, array(
  55. 'template' => 'LeafletBundle:CRUD:map_show_field.html.twig',
  56. 'translation_domain' => 'MapBundle',
  57. ))
  58. ->end()
  59. ->end();
  60. }
  61. }
  62. }
  63. }