1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vivait\BootstrapBundle\EventListener; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
6
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
7
|
|
|
use Vivait\Common\Event\EntityEvent; |
8
|
|
|
|
9
|
|
|
class EntityFlashBagListener { |
10
|
|
|
/** |
11
|
|
|
* @var Session |
12
|
|
|
*/ |
13
|
|
|
private $session; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var TranslatorInterface |
17
|
|
|
*/ |
18
|
|
|
private $translator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param Session $session |
22
|
|
|
* @param TranslatorInterface $translator |
23
|
|
|
*/ |
24
|
|
|
public function __construct(Session $session, TranslatorInterface $translator) |
25
|
|
|
{ |
26
|
|
|
$this->session = $session; |
27
|
|
|
$this->translator = $translator; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param \Vivait\Common\Event\EntityEvent $event |
32
|
|
|
*/ |
33
|
|
|
public function onEntityModifiedEvent(EntityEvent $event) |
34
|
|
|
{ |
35
|
|
|
$this->getFlashBag()->add('success', $this->translator->trans('The %entity_name% has been modified successfully!', [ |
36
|
|
|
'%entity_name%' => $event::getEntityTypeLabel() |
37
|
|
|
])); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param \Vivait\Common\Event\EntityEvent $event |
42
|
|
|
*/ |
43
|
|
|
public function onEntityCreatedEvent(EntityEvent $event) |
44
|
|
|
{ |
45
|
|
|
$this->getFlashBag()->add('success', $this->translator->trans('The %entity_name% has been created successfully!', [ |
46
|
|
|
'%entity_name%' => $event::getEntityTypeLabel() |
47
|
|
|
])); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param \Vivait\Common\Event\EntityEvent $event |
52
|
|
|
*/ |
53
|
|
|
public function onEntityDeletedEvent(EntityEvent $event) |
54
|
|
|
{ |
55
|
|
|
$this->getFlashBag()->add('success', $this->translator->trans('The %entity_name% has been deleted', [ |
56
|
|
|
'%entity_name%' => $event::getEntityTypeLabel() |
57
|
|
|
])); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface |
62
|
|
|
*/ |
63
|
|
|
private function getFlashBag() { |
64
|
|
|
return $this->session->getFlashBag(); |
65
|
|
|
} |
66
|
|
|
} |