-
Notifications
You must be signed in to change notification settings - Fork 1
/
EasyAdminSubscriber.php
52 lines (45 loc) · 1.45 KB
/
EasyAdminSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This file is part of Eventbase API.
*
* (c) 2017–2018 ITK Development
*
* This source file is subject to the MIT license.
*/
namespace AdminBundle\EventSubscriber;
use AdminBundle\Service\TagManager;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class EasyAdminSubscriber implements EventSubscriberInterface
{
private $tagManager;
private $container;
public function __construct(TagManager $tagManager, ContainerInterface $container)
{
$this->tagManager = $tagManager;
$this->container = $container;
}
public static function getSubscribedEvents()
{
return [
EasyAdminEvents::POST_INITIALIZE => ['addQueryParameters'],
];
}
public function addQueryParameters(GenericEvent $event)
{
$request = $event->getArgument('request');
if ($request) {
$action = $request->get('action', 'list');
$entity = $event->getArgument('entity');
if (isset($entity[$action]['params'])) {
foreach ($entity[$action]['params'] as $name => $value) {
if (!$request->query->has($name)) {
$request->query->add([$name => $value]);
}
}
}
}
}
}