AdminEventExtension.php 4.0 KB

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