Skip to content

Commit c94c8b6

Browse files
Init basic docs about admin bundle
1 parent 17807b1 commit c94c8b6

File tree

3 files changed

+161
-2
lines changed

3 files changed

+161
-2
lines changed

_themes/sulu/static/sulu.css_t

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ div.toctree-wrapper a {
188188
}
189189

190190
div.toctree-wrapper a {
191-
color: #112a46;
192-
text-decoration: none;
191+
color: #52B6CA;
192+
text-decoration: underline;
193193
}
194194

195195
div.toctree-wrapper a:hover {

bundles/admin/index.rst

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
AdminBundle
2+
============
3+
4+
The AdminBundle provides all functionality for the Sulu Admin UI. It allows
5+
to extend the Admin UI to integrate custom functionality or modify existing
6+
views with new functionality.
7+
8+
The Admin Class
9+
---------------
10+
11+
The Admin class is the main entry point for the Admin UI. It is responsible
12+
to configure Navigation Items, Views, Security and other parts of the Admin UI.
13+
14+
It is best practice to create one Admin class per resource type, e.g. one for an
15+
``Event`` resource.
16+
17+
.. code-block:: php
18+
19+
<?php
20+
21+
namespace App\Admin;
22+
23+
use Sulu\Bundle\AdminBundle\Admin\Admin;
24+
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
25+
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
26+
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
27+
28+
class EventAdmin extends Admin
29+
{
30+
public function __construct(private ViewBuilderFactoryInterface $viewBuilderFactory)
31+
{
32+
}
33+
34+
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
35+
{
36+
// add navigation items
37+
}
38+
39+
public function configureViews(ViewCollection $viewCollection): void
40+
{
41+
// add views
42+
}
43+
44+
public function getSecurityContexts(): array
45+
{
46+
return [];
47+
}
48+
}
49+
50+
Navigation Items
51+
----------------
52+
53+
Navigation Items are the items in the left sidebar of the Admin UI. They are configurable
54+
and are linking to different views.
55+
56+
.. code-block:: php
57+
58+
<?php
59+
60+
namespace App\Admin;
61+
62+
use Sulu\Bundle\AdminBundle\Admin\Admin;
63+
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
64+
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
65+
66+
class EventAdmin extends Admin
67+
{
68+
public const LIST_VIEW = 'app_event.list';
69+
70+
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
71+
{
72+
$item = new NavigationItem('app.events'); // translation key inside the admin translation domain
73+
$item->setPosition(70);
74+
$item->setIcon('su-clock'); // icon from Sulu icon font or font awesome seehttps://jsdocs.sulu.io/2.5/#icon
75+
$item->setView(static::LIST_VIEW);
76+
77+
$navigationItemCollection->add($item);
78+
}
79+
80+
// ...
81+
}
82+
83+
Every item can have a title, an icon, a position and a view. The view is the key which best practices is
84+
to reference by a constants which you also use in the View Builder tackled later in this documentations.
85+
86+
Security Checker
87+
----------------
88+
89+
If you have different user roles you want to make sure only specific users see specific navigation items or view.
90+
Via injecting the securityChecker service and providing new security context it is possible to check if a user
91+
has permissions for a specific security context.
92+
93+
.. code-block:: php
94+
95+
<?php
96+
97+
namespace App\Admin;
98+
99+
use Sulu\Bundle\AdminBundle\Admin\Admin;
100+
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
101+
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
102+
use Sulu\Component\Security\Authorization\PermissionTypes;
103+
104+
class EventAdmin extends Admin
105+
{
106+
public const SECURITY_CONTEXT = 'sulu.event.events';
107+
108+
public function __construct(
109+
private SecurityCheckerInterface $securityChecker,
110+
) {
111+
}
112+
113+
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
114+
{
115+
if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::EDIT)) {
116+
// add navigation items
117+
}
118+
}
119+
120+
public function configureViews(ViewCollection $viewCollection): void
121+
{
122+
if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::EDIT)) {
123+
// add views
124+
}
125+
}
126+
127+
public function getSecurityContexts()
128+
{
129+
return [
130+
self::SULU_ADMIN_SECURITY_SYSTEM => [
131+
'Event' => [
132+
self::SECURITY_CONTEXT => [
133+
PermissionTypes::VIEW,
134+
PermissionTypes::ADD,
135+
PermissionTypes::EDIT,
136+
PermissionTypes::DELETE,
137+
],
138+
],
139+
],
140+
];
141+
}
142+
}
143+
144+
Views
145+
-----
146+
147+
Views are the main content of the Admin UI. They are configurable and required to extend the Admin UI
148+
with new tabs and navigation items.
149+
150+
List View Builder
151+
~~~~~~~~~~~~~~~~~
152+
153+
ToDo
154+
155+
Form View Builder
156+
~~~~~~~~~~~~~~~~~
157+
158+
ToDo

bundles/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ documented the most important ones.
1111
:maxdepth: 2
1212

1313
activity
14+
admin/index
1415
audience_targeting
1516
category
1617
contact

0 commit comments

Comments
 (0)