AdminEventExtension.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /**
  20. * Class AdminEventExtension.
  21. *
  22. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  23. */
  24. class AdminEventExtension extends AdminExtension
  25. {
  26. protected $eventDispatcher;
  27. /**
  28. * @param EventDispatcherInterface $eventDispatcher
  29. */
  30. public function __construct(EventDispatcherInterface $eventDispatcher)
  31. {
  32. $this->eventDispatcher = $eventDispatcher;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function configureFormFields(FormMapper $form)
  38. {
  39. $this->eventDispatcher->dispatch('sonata.admin.event.configure.form', new ConfigureEvent($form->getAdmin(), $form, ConfigureEvent::TYPE_FORM));
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function configureListFields(ListMapper $list)
  45. {
  46. $this->eventDispatcher->dispatch('sonata.admin.event.configure.list', new ConfigureEvent($list->getAdmin(), $list, ConfigureEvent::TYPE_LIST));
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function configureDatagridFilters(DatagridMapper $filter)
  52. {
  53. $this->eventDispatcher->dispatch('sonata.admin.event.configure.datagrid', new ConfigureEvent($filter->getAdmin(), $filter, ConfigureEvent::TYPE_DATAGRID));
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function configureShowFields(ShowMapper $show)
  59. {
  60. $this->eventDispatcher->dispatch('sonata.admin.event.configure.show', new ConfigureEvent($show->getAdmin(), $show, ConfigureEvent::TYPE_SHOW));
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list')
  66. {
  67. $this->eventDispatcher->dispatch('sonata.admin.event.configure.query', new ConfigureQueryEvent($admin, $query, $context));
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function preUpdate(AdminInterface $admin, $object)
  73. {
  74. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_update', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_UPDATE));
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function postUpdate(AdminInterface $admin, $object)
  80. {
  81. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_update', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_UPDATE));
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function prePersist(AdminInterface $admin, $object)
  87. {
  88. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_persist', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_PERSIST));
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function postPersist(AdminInterface $admin, $object)
  94. {
  95. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_persist', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_PERSIST));
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function preRemove(AdminInterface $admin, $object)
  101. {
  102. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.pre_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_PRE_REMOVE));
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function postRemove(AdminInterface $admin, $object)
  108. {
  109. $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_REMOVE));
  110. }
  111. }