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.     private EventDispatcherInterface $eventDispatcher;
  28.     public function __construct(EventDispatcherInterface $eventDispatcher)
  29.     {
  30.         $this->eventDispatcher $eventDispatcher;
  31.     }
  32.     public function configureFormFields(FormMapper $form): void
  33.     {
  34.         $this->eventDispatcher->dispatch(
  35.             new ConfigureEvent($form->getAdmin(), $formConfigureEvent::TYPE_FORM),
  36.             'sonata.admin.event.configure.form'
  37.         );
  38.     }
  39.     public function configureListFields(ListMapper $list): void
  40.     {
  41.         $this->eventDispatcher->dispatch(
  42.             new ConfigureEvent($list->getAdmin(), $listConfigureEvent::TYPE_LIST),
  43.             'sonata.admin.event.configure.list'
  44.         );
  45.     }
  46.     public function configureDatagridFilters(DatagridMapper $filter): void
  47.     {
  48.         $this->eventDispatcher->dispatch(
  49.             new ConfigureEvent($filter->getAdmin(), $filterConfigureEvent::TYPE_DATAGRID),
  50.             'sonata.admin.event.configure.datagrid'
  51.         );
  52.     }
  53.     public function configureShowFields(ShowMapper $show): void
  54.     {
  55.         $this->eventDispatcher->dispatch(
  56.             new ConfigureEvent($show->getAdmin(), $showConfigureEvent::TYPE_SHOW),
  57.             'sonata.admin.event.configure.show'
  58.         );
  59.     }
  60.     public function configureQuery(AdminInterface $adminProxyQueryInterface $querystring $context 'list'): void
  61.     {
  62.         $this->eventDispatcher->dispatch(
  63.             new ConfigureQueryEvent($admin$query$context),
  64.             'sonata.admin.event.configure.query'
  65.         );
  66.     }
  67.     public function preUpdate(AdminInterface $adminobject $object): void
  68.     {
  69.         $this->eventDispatcher->dispatch(
  70.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_PRE_UPDATE),
  71.             'sonata.admin.event.persistence.pre_update'
  72.         );
  73.     }
  74.     public function postUpdate(AdminInterface $adminobject $object): void
  75.     {
  76.         $this->eventDispatcher->dispatch(
  77.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_POST_UPDATE),
  78.             'sonata.admin.event.persistence.post_update'
  79.         );
  80.     }
  81.     public function prePersist(AdminInterface $adminobject $object): void
  82.     {
  83.         $this->eventDispatcher->dispatch(
  84.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_PRE_PERSIST),
  85.             'sonata.admin.event.persistence.pre_persist'
  86.         );
  87.     }
  88.     public function postPersist(AdminInterface $adminobject $object): void
  89.     {
  90.         $this->eventDispatcher->dispatch(
  91.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_POST_PERSIST),
  92.             'sonata.admin.event.persistence.post_persist'
  93.         );
  94.     }
  95.     public function preRemove(AdminInterface $adminobject $object): void
  96.     {
  97.         $this->eventDispatcher->dispatch(
  98.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_PRE_REMOVE),
  99.             'sonata.admin.event.persistence.pre_remove'
  100.         );
  101.     }
  102.     public function postRemove(AdminInterface $adminobject $object): void
  103.     {
  104.         $this->eventDispatcher->dispatch(
  105.             new PersistenceEvent($admin$objectPersistenceEvent::TYPE_POST_REMOVE),
  106.             'sonata.admin.event.persistence.post_remove'
  107.         );
  108.     }
  109.     public function preBatchAction(AdminInterface $adminstring $actionNameProxyQueryInterface $query, array &$idxbool $allElements): void
  110.     {
  111.         $this->eventDispatcher->dispatch(
  112.             new BatchActionEvent($adminBatchActionEvent::TYPE_PRE_BATCH_ACTION$actionName$query$idx$allElements),
  113.             'sonata.admin.event.batch_action.pre_batch_action'
  114.         );
  115.     }
  116. }