Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init basic docs about admin bundle #824

Draft
wants to merge 1 commit into
base: 2.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _themes/sulu/static/sulu.css_t
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ div.toctree-wrapper a {
}

div.toctree-wrapper a {
color: #112a46;
text-decoration: none;
color: #52B6CA;
text-decoration: underline;
}

div.toctree-wrapper a:hover {
Expand Down
158 changes: 158 additions & 0 deletions bundles/admin/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
AdminBundle
============

The AdminBundle provides all functionality for the Sulu Admin UI. It allows
to extend the Admin UI to integrate custom functionality or modify existing
views with new functionality.

The Admin Class
---------------

The Admin class is the main entry point for the Admin UI. It is responsible
to configure Navigation Items, Views, Security and other parts of the Admin UI.

It is best practice to create one Admin class per resource type, e.g. one for an
``Event`` resource.

.. code-block:: php

<?php

namespace App\Admin;

use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;

class EventAdmin extends Admin
{
public function __construct(private ViewBuilderFactoryInterface $viewBuilderFactory)
{
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
{
// add navigation items
}

public function configureViews(ViewCollection $viewCollection): void
{
// add views
}

public function getSecurityContexts(): array
{
return [];
}
}

Navigation Items
----------------

Navigation Items are the items in the left sidebar of the Admin UI. They are configurable
and are linking to different views.

.. code-block:: php

<?php

namespace App\Admin;

use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;

class EventAdmin extends Admin
{
public const LIST_VIEW = 'app_event.list';

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
{
$item = new NavigationItem('app.events'); // translation key inside the admin translation domain
$item->setPosition(70);
$item->setIcon('su-clock'); // icon from Sulu icon font or font awesome seehttps://jsdocs.sulu.io/2.5/#icon
$item->setView(static::LIST_VIEW);

$navigationItemCollection->add($item);
}

// ...
}

Every item can have a title, an icon, a position and a view. The view is the key which best practices is
to reference by a constants which you also use in the View Builder tackled later in this documentations.

Security Checker
----------------

If you have different user roles you want to make sure only specific users see specific navigation items or view.
Via injecting the securityChecker service and providing new security context it is possible to check if a user
has permissions for a specific security context.

.. code-block:: php

<?php

namespace App\Admin;

use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
use Sulu\Component\Security\Authorization\PermissionTypes;

class EventAdmin extends Admin
{
public const SECURITY_CONTEXT = 'sulu.event.events';

public function __construct(
private SecurityCheckerInterface $securityChecker,
) {
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
{
if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::EDIT)) {
// add navigation items
}
}

public function configureViews(ViewCollection $viewCollection): void
{
if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::EDIT)) {
// add views
}
}

public function getSecurityContexts()
{
return [
self::SULU_ADMIN_SECURITY_SYSTEM => [
'Event' => [
self::SECURITY_CONTEXT => [
PermissionTypes::VIEW,
PermissionTypes::ADD,
PermissionTypes::EDIT,
PermissionTypes::DELETE,
],
],
],
];
}
}

Views
-----

Views are the main content of the Admin UI. They are configurable and required to extend the Admin UI
with new tabs and navigation items.

List View Builder
~~~~~~~~~~~~~~~~~

ToDo

Form View Builder
~~~~~~~~~~~~~~~~~

ToDo
1 change: 1 addition & 0 deletions bundles/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ documented the most important ones.
:maxdepth: 2

activity
admin/index
audience_targeting
category
contact
Expand Down
Loading