1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Zicht Online <http://zicht.nl> |
4
|
|
|
*/ |
5
|
|
|
namespace Zicht\Bundle\PageBundle\AdminMenu; |
6
|
|
|
|
7
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
8
|
|
|
use Symfony\Component\EventDispatcher\Event; |
9
|
|
|
use Zicht\Bundle\AdminBundle\Event\AdminEvents; |
10
|
|
|
use Zicht\Bundle\AdminBundle\Event\MenuEvent; |
11
|
|
|
use Zicht\Bundle\AdminBundle\Event\PropagationInterface; |
12
|
|
|
use Zicht\Bundle\PageBundle\Event\PageViewEvent; |
13
|
|
|
use Zicht\Bundle\UrlBundle\Url\Provider; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Add links to edit a page to the zicht admin menu |
17
|
|
|
*/ |
18
|
|
|
class EventPropagationBuilder implements PropagationInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Pool |
22
|
|
|
*/ |
23
|
|
|
protected $sonata; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Provider |
27
|
|
|
*/ |
28
|
|
|
protected $pageUrlProvider; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Construct with the specified admin pool |
32
|
|
|
* |
33
|
|
|
* @param Pool $sonata |
34
|
|
|
* @param Provider $pageUrlProvider |
35
|
|
|
*/ |
36
|
4 |
|
public function __construct(Pool $sonata = null, Provider $pageUrlProvider = null) |
37
|
|
|
{ |
38
|
4 |
|
$this->sonata = $sonata; |
39
|
4 |
|
$this->pageUrlProvider = $pageUrlProvider; |
40
|
4 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Build the relevant event and forward it. |
44
|
|
|
* |
45
|
|
|
* @param \Symfony\Component\EventDispatcher\Event $event |
46
|
|
|
* @return null|void |
47
|
|
|
*/ |
48
|
4 |
|
public function buildAndForwardEvent(Event $event) |
49
|
|
|
{ |
50
|
4 |
|
if (!$event instanceof PageViewEvent) { |
51
|
1 |
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
$page = $event->getPage(); |
55
|
3 |
|
$admin = $this->sonata->getAdminByClass(get_class($page)); |
56
|
|
|
|
57
|
3 |
|
if ($admin === null) { |
58
|
2 |
|
$admin = $this->sonata->getAdminByClass(get_parent_class($page)); |
59
|
2 |
|
} |
60
|
|
|
|
61
|
3 |
|
if ($page->getId() && $admin !== null) { |
62
|
1 |
|
$title = $event->getPage()->getTitle(); |
63
|
|
|
/** @var \Zicht\Bundle\PageBundle\Event\PageViewEvent $event */ |
64
|
1 |
|
$event->getDispatcher()->dispatch( |
|
|
|
|
65
|
1 |
|
AdminEvents::MENU_EVENT, |
66
|
1 |
|
new MenuEvent( |
67
|
1 |
|
$admin->generateObjectUrl('edit', $event->getPage()), |
68
|
1 |
|
sprintf( |
69
|
1 |
|
'Beheer pagina "%s"', |
70
|
1 |
|
strlen($title) > 20 ? substr($title, 0, 20) . '...' : $title |
71
|
1 |
|
) |
72
|
1 |
|
) |
73
|
1 |
|
); |
74
|
1 |
|
} |
75
|
3 |
|
} |
76
|
|
|
} |
77
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.