AdminEventExtension.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Event;
  11. use Sonata\AdminBundle\Admin\AdminExtension;
  12. use Sonata\AdminBundle\Admin\AdminInterface;
  13. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  14. use Sonata\AdminBundle\Datagrid\ListMapper;
  15. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  16. use Sonata\AdminBundle\Form\FormMapper;
  17. use Sonata\AdminBundle\Show\ShowMapper;
  18. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  19. class AdminEventExtension extends AdminExtension
  20. {
  21. protected $eventDispatcher;
  22. /**
  23. * @param EventDispatcherInterface $eventDispatcher
  24. */
  25. public function __construct(EventDispatcherInterface $eventDispatcher)
  26. {
  27. $this->eventDispatcher = $eventDispatcher;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function configureFormFields(FormMapper $form)
  33. {
  34. $this->eventDispatcher->dispatch('sonata.admin.event.configure.form', new ConfigureEvent($form->getAdmin(), $form, ConfigureEvent::TYPE_FORM));
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function configureListFields(ListMapper $list)
  40. {
  41. $this->eventDispatcher->dispatch('sonata.admin.event.configure.list', new ConfigureEvent($list->getAdmin(), $list, ConfigureEvent::TYPE_LIST));
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function configureDatagridFilters(DatagridMapper $filter)
  47. {
  48. $this->eventDispatcher->dispatch('sonata.admin.event.configure.datagrid', new ConfigureEvent($filter->getAdmin(), $filter, ConfigureEvent::TYPE_DATAGRID));
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function configureShowFields(ShowMapper $show)
  54. {
  55. $this->eventDispatcher->dispatch('sonata.admin.event.configure.show', new ConfigureEvent($show->getAdmin(), $show, ConfigureEvent::TYPE_SHOW));
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list')
  61. {
  62. $this->eventDispatcher->dispatch('sonata.admin.event.configure.query', new ConfigureQueryEvent($admin, $query, $context));
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function preUpdate(AdminInterface $admin, $object)
  68. {
  69. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_update', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_UPDATE));
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function postUpdate(AdminInterface $admin, $object)
  75. {
  76. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_update', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_UPDATE));
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function prePersist(AdminInterface $admin, $object)
  82. {
  83. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_persist', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_PERSIST));
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function postPersist(AdminInterface $admin, $object)
  89. {
  90. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_persist', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_PERSIST));
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function preRemove(AdminInterface $admin, $object)
  96. {
  97. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_REMOVE));
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function postRemove(AdminInterface $admin, $object)
  103. {
  104. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_REMOVE));
  105. }
  106. }