66use Symfony \Component \Form \Form ;
77use Symfony \Component \Form \FormInterface ;
88use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
9+ use Symfony \Contracts \EventDispatcher \Event as ContractsEvent ;
910use Lexik \Bundle \FormFilterBundle \Filter \Condition \ConditionBuilder ;
1011use Lexik \Bundle \FormFilterBundle \Filter \Condition \ConditionBuilderInterface ;
1112use Lexik \Bundle \FormFilterBundle \Filter \Condition \ConditionInterface ;
@@ -85,7 +86,7 @@ public function addFilterConditions(FormInterface $form, $queryBuilder, $alias =
8586 {
8687 // create the right QueryInterface object
8788 $ event = new PrepareEvent ($ queryBuilder );
88- $ this ->dispatcher -> dispatch (FilterEvents::PREPARE , $ event );
89+ $ this ->dispatch (FilterEvents::PREPARE , $ event );
8990
9091 if (!$ event ->getFilterQuery () instanceof QueryInterface) {
9192 throw new \RuntimeException ("Couldn't find any filter query object. " );
@@ -103,7 +104,7 @@ public function addFilterConditions(FormInterface $form, $queryBuilder, $alias =
103104
104105 // walk condition nodes to add condition on the query builder instance
105106 $ name = sprintf ('lexik_filter.apply_filters.%s ' , $ event ->getFilterQuery ()->getEventPartName ());
106- $ this ->dispatcher -> dispatch ($ name , new ApplyFilterConditionEvent ($ queryBuilder , $ this ->conditionBuilder ));
107+ $ this ->dispatch ($ name , new ApplyFilterConditionEvent ($ queryBuilder , $ this ->conditionBuilder ));
107108
108109 $ this ->conditionBuilder = null ;
109110
@@ -207,7 +208,7 @@ protected function getFilterCondition(FormInterface $form, AbstractType $formTyp
207208 }
208209
209210 $ event = new GetFilterConditionEvent ($ filterQuery , $ field , $ values );
210- $ this ->dispatcher -> dispatch ($ eventName , $ event );
211+ $ this ->dispatch ($ eventName , $ event );
211212
212213 $ condition = $ event ->getCondition ();
213214 }
@@ -288,4 +289,19 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface
288289 }
289290 }
290291 }
292+
293+ /**
294+ * @param string|object $eventName
295+ * @param string|object $event
296+ *
297+ * @return mixed
298+ */
299+ protected function dispatch ($ eventName , $ event )
300+ {
301+ if ($ event instanceof ContractsEvent) {
302+ return $ this ->dispatcher ->dispatch ($ event , $ eventName );
303+ } else {
304+ return $ this ->dispatcher ->dispatch ($ eventName , $ event );
305+ }
306+ }
291307}
0 commit comments