LocationListener.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  36. * @param ConfigureEvent $event
  37. */
  38. public function configureShowFields(ConfigureEvent $event)
  39. {
  40. $mapper = $event->getMapper();
  41. $subject = $mapper->getAdmin()->getSubject();
  42. if ($subject && $subject instanceof LocationInterface) {
  43. if ($mapper->hasOpenTab()) {
  44. $mapper
  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. }
  64. }