vendor/sonata-project/admin-bundle/src/Event/AdminEventExtension.php line 30

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