1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\MenuBundle\AdminList; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
7
|
|
|
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper; |
8
|
|
|
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator; |
9
|
|
|
use Kunstmaan\MenuBundle\Entity\Menu; |
10
|
|
|
use Kunstmaan\MenuBundle\Entity\MenuItem; |
11
|
|
|
|
12
|
|
|
class MenuItemAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Menu |
16
|
|
|
*/ |
17
|
|
|
private $menu; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param EntityManager $em The entity manager |
21
|
|
|
* @param AclHelper $aclHelper The acl helper |
|
|
|
|
22
|
|
|
* @param Menu $menu |
23
|
|
|
*/ |
24
|
|
|
public function __construct(EntityManager $em, AclHelper $aclHelper = null, Menu $menu) |
25
|
|
|
{ |
26
|
|
|
parent::__construct($em, $aclHelper); |
27
|
|
|
|
28
|
|
|
$this->setListTemplate('KunstmaanMenuBundle:AdminList:list-menu-item.html.twig'); |
29
|
|
|
$this->setAddTemplate('KunstmaanMenuBundle:AdminList:edit-menu-item.html.twig'); |
30
|
|
|
$this->setEditTemplate('KunstmaanMenuBundle:AdminList:edit-menu-item.html.twig'); |
31
|
|
|
$this->menu = $menu; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Configure the visible columns |
36
|
|
|
*/ |
37
|
|
|
public function buildFields() |
38
|
|
|
{ |
39
|
|
|
$this->addField('title', 'kuma_menu.menu_item.adminlist.field.title', false, 'KunstmaanMenuBundle:AdminList:menu-item-title.html.twig'); |
40
|
|
|
$this->addField('online', 'kuma_menu.menu_item.adminlist.field.online', false, 'KunstmaanMenuBundle:AdminList:menu-item-online.html.twig'); |
41
|
|
|
$this->addField('type', 'kuma_menu.menu_item.adminlist.field.type', false); |
42
|
|
|
$this->addField('url', 'kuma_menu.menu_item.adminlist.field.url', false, 'KunstmaanMenuBundle:AdminList:menu-item-url.html.twig'); |
43
|
|
|
$this->addField('newWindow', 'kuma_menu.menu_item.adminlist.field.new_window', false); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get bundle name |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getBundleName() |
52
|
|
|
{ |
53
|
|
|
return 'KunstmaanMenuBundle'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get entity name |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getEntityName() |
62
|
|
|
{ |
63
|
|
|
return 'MenuItem'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param QueryBuilder $qb |
68
|
|
|
*/ |
69
|
|
|
public function adaptQueryBuilder(QueryBuilder $qb) |
70
|
|
|
{ |
71
|
|
|
$qb->andWhere('b.menu = :menu'); |
72
|
|
|
$qb->setParameter('menu', $this->menu); |
73
|
|
|
$qb->orderBy('b.lft', 'ASC'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param array|object $item The item |
78
|
|
|
* @param string $columnName The column name |
79
|
|
|
* |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
|
|
public function getValue($item, $columnName) |
83
|
|
|
{ |
84
|
|
|
if ($columnName == 'title') { |
85
|
|
|
return $item->getDisplayTitle(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($columnName == 'online') { |
89
|
|
|
return $item; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($columnName == 'type') { |
93
|
|
|
if ($item->getType() == MenuItem::TYPE_PAGE_LINK) { |
94
|
|
|
return 'Page link'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return 'External link'; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($columnName == 'url') { |
101
|
|
|
return $item; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return parent::getValue($item, $columnName); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Return extra parameters for use in list actions. |
109
|
|
|
* |
110
|
|
|
* @return array |
|
|
|
|
111
|
|
|
*/ |
112
|
|
|
public function getExtraParameters() |
113
|
|
|
{ |
114
|
|
|
return array('menuid' => $this->menu->getId()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* You can override this method to do some custom things you need to do when adding an entity |
119
|
|
|
* |
120
|
|
|
* @param object $entity |
121
|
|
|
* |
122
|
|
|
* @return mixed |
|
|
|
|
123
|
|
|
*/ |
124
|
|
|
public function decorateNewEntity($entity) |
125
|
|
|
{ |
126
|
|
|
$entity->setMenu($this->menu); |
127
|
|
|
|
128
|
|
|
return $entity; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getMenu() |
132
|
|
|
{ |
133
|
|
|
return $this->menu; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return int |
138
|
|
|
*/ |
139
|
|
|
public function getLimit() |
140
|
|
|
{ |
141
|
|
|
return 1000; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.