Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
added admin-class, navigation and route-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Jun 28, 2018
1 parent e32d294 commit 22e3c6a
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 4 deletions.
48 changes: 48 additions & 0 deletions Admin/EventAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ExampleEventBundle\Admin;

use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Routing\Route;
use Sulu\Bundle\AdminBundle\Navigation\Navigation;
use Sulu\Bundle\AdminBundle\Navigation\NavigationItem;

class EventAdmin extends Admin
{
public function getNavigation(): Navigation
{
$rootNavigationItem = $this->getNavigationItemRoot();

$module = new NavigationItem('example_event.events');
$module->setPosition(40);
$module->setIcon('su-calendar');

$events = new NavigationItem('example_event.events');
$events->setPosition(10);
$events->setMainRoute('example_event.event_datagrid');

$module->addChild($events);
$rootNavigationItem->addChild($module);

return new Navigation($rootNavigationItem);
}

public function getRoutes(): array
{
return [
(new Route('example_event.event_datagrid', '/events', 'sulu_admin.datagrid'))
->addOption('title', 'example_event.events')
->addOption('adapters', ['table'])
->addOption('resourceKey', 'events'),
];
}
}
28 changes: 28 additions & 0 deletions DependencyInjection/ExampleEventExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sulu\Bundle\ExampleEventBundle\DependencyInjection;

use Sulu\Bundle\ExampleEventBundle\Model\Event;
use Sulu\Component\HttpKernel\SuluKernel;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand Down Expand Up @@ -73,5 +75,31 @@ public function prepend(ContainerBuilder $container)
],
]
);

$this->prependAdmin($container);
}

private function prependAdmin(ContainerBuilder $container)
{
if (SuluKernel::CONTEXT_ADMIN !== $container->getParameter('sulu.context')) {
return;
}

if (!$container->hasExtension('sulu_admin')) {
throw new \RuntimeException('Missing SuluAdminBundle.');
}

$container->prependExtensionConfig(
'sulu_admin',
[
'resources' => [
'events' => [
'form' => [],
'datagrid' => Event::class,
'endpoint' => 'sulu_example_event.get_events',
],
],
]
);
}
}
18 changes: 14 additions & 4 deletions Resources/config/list-builder/Event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@
<orm:entity-name>Sulu\Bundle\ExampleEventBundle\Model\Event</orm:entity-name>
</property>

<property name="created" list:translation="example_event.created" list:type="datetime" visibility="yes">
<property name="startDate" visibility="always" list:translation="example_event.start-date" list:type="date">
<orm:field-name>startDate</orm:field-name>
<orm:entity-name>Sulu\Bundle\ExampleEventBundle\Model\Event</orm:entity-name>
</property>

<property name="endDate" visibility="always" list:translation="example_event.end-date" list:type="date">
<orm:field-name>endDate</orm:field-name>
<orm:entity-name>Sulu\Bundle\ExampleEventBundle\Model\Event</orm:entity-name>
</property>

<property name="created" visibility="yes" list:translation="example_event.created" list:type="datetime">
<orm:field-name>created</orm:field-name>
<orm:entity-name>Sulu\Bundle\ExampleEventBundle\Model\Event</orm:entity-name>
</property>

<concatenation-property name="creator" list:translation="example_event.creator" visibility="yes" searchability="yes">
<concatenation-property name="creator" visibility="yes" searchability="yes" list:translation="example_event.creator">
<orm:field>
<orm:field-name>firstName</orm:field-name>
<orm:entity-name>%sulu.model.contact.class%_creator</orm:entity-name>
Expand All @@ -54,12 +64,12 @@
</orm:field>
</concatenation-property>

<property name="changed" list:translation="example_event.changed" list:type="datetime" visibility="yes">
<property name="changed" visibility="yes" list:translation="example_event.changed" list:type="datetime">
<orm:field-name>changed</orm:field-name>
<orm:entity-name>Sulu\Bundle\ExampleEventBundle\Model\Event</orm:entity-name>
</property>

<concatenation-property name="changer" list:translation="example_event.changer" visibility="yes" searchability="yes">
<concatenation-property visibility="yes" searchability="yes" name="changer" list:translation="example_event.changer">
<orm:field>
<orm:field-name>firstName</orm:field-name>
<orm:entity-name>%sulu.model.contact.class%_changer</orm:entity-name>
Expand Down
8 changes: 8 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sulu_example_event.admin"
class="Sulu\Bundle\ExampleEventBundle\Admin\EventAdmin">
<argument>%sulu_admin.name%</argument>

<tag name="sulu.admin"/>
<tag name="sulu.context" context="admin"/>
</service>

<service id="sulu_example_event.controller.event"
class="Sulu\Bundle\ExampleEventBundle\Controller\EventController">
<argument type="service" id="sulu_example_event.commandbus"/>
Expand Down
10 changes: 10 additions & 0 deletions Resources/translations/sulu/admin.de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"example_event.events": "Veranstaltungen",
"example_event.title": "Titel",
"example_event.start-date": "Start",
"example_event.end-date": "Ende",
"example_event.created": "Erstellt am",
"example_event.creator": "Erstellt von",
"example_event.changed": "Bearbeitet am",
"example_event.changer": "Bearbeitet von"
}
10 changes: 10 additions & 0 deletions Resources/translations/sulu/admin.en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"example_event.events": "Events",
"example_event.title": "Title",
"example_event.start-date": "Start",
"example_event.end-date": "End",
"example_event.created": "Created at",
"example_event.creator": "Created by",
"example_event.changed": "Changed at",
"example_event.changer": "Changed by"
}
3 changes: 3 additions & 0 deletions Resources/translations/sulu/admin_backend.de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"example_event.events": "Veranstaltungen"
}
3 changes: 3 additions & 0 deletions Resources/translations/sulu/admin_backend.en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"example_event.event": "Events"
}

0 comments on commit 22e3c6a

Please sign in to comment.