Skip to content

Commit 2f40348

Browse files
committed
admin menu improvements
1 parent ff1deea commit 2f40348

File tree

25 files changed

+409
-152
lines changed

25 files changed

+409
-152
lines changed

app/base/abstracts/Controllers/AdminPage.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use App\Site\Routing\RouteInfo;
2828
use App\Site\Models\AdminActionLog;
2929
use App\App;
30+
use App\Base\Controllers\Dummy\NullPage;
31+
use League\Plates\Template\Func;
3032
use Throwable;
3133

3234
/**
@@ -74,6 +76,17 @@ public static function getRouteVerbs(): array
7476
return ['GET', 'POST'];
7577
}
7678

79+
80+
/**
81+
* returns admin sidebar link info array, if any
82+
*
83+
* @return array|null
84+
*/
85+
public Function getAdminPageLink() : array|null
86+
{
87+
return null;
88+
}
89+
7790
/**
7891
* before render hook
7992
*

app/base/tools/Plates/SiteBase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,14 @@ public function getPageRegions(): array
328328
{
329329
return $this->getSiteData()->getPageRegions();
330330
}
331+
332+
/**
333+
* returns admin links for sidebar
334+
*
335+
* @return array
336+
*/
337+
public function getAdminSidebarMenu() : array
338+
{
339+
return $this->getSiteData()->getAdminSidebarMenu();
340+
}
331341
}

app/base/tools/Utils/SiteData.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use DI\DependencyException;
2323
use DI\NotFoundException;
2424
use Exception;
25+
use HaydenPierce\ClassFinder\ClassFinder;
2526
use Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException;
2627
use App\Site\Models\Website;
2728
use LessQL\Row;
@@ -578,4 +579,38 @@ protected function menuElementToArray(Menu $menu_element): array
578579

579580
return $out;
580581
}
582+
583+
public function getAdminSidebarMenu(bool $reset = false) : array
584+
{
585+
$links = [];
586+
587+
$admin_links_key = "admin.links";
588+
if (!$this->getCache()->has($admin_links_key) || $reset) {
589+
$controllerClasses = ClassFinder::getClassesInNamespace('App\Site\Controllers', ClassFinder::RECURSIVE_MODE);
590+
foreach ($controllerClasses as $controllerClass) {
591+
if (method_exists($controllerClass, 'getAdminPageLink')) {
592+
$adminLink = $this->getContainer()->call([$controllerClass, 'getAdminPageLink']) ?? null;
593+
if ($adminLink) {
594+
$links[$adminLink['section']][] = $adminLink;
595+
}
596+
}
597+
}
598+
599+
$this->getCache()->set($admin_links_key, $links);
600+
} else {
601+
$links = $this->getCache()->get($admin_links_key);
602+
}
603+
604+
foreach ($links as $sectionName => $sectionLinks) {
605+
usort($links[$sectionName], function ($a, $b) {
606+
if (isset($a['order']) && isset($b['order'])) {
607+
return $a['order'] <=> $b['order'];
608+
}
609+
return ($a['text'] ?? '') <=> ($b['text'] ?? '');
610+
});
611+
}
612+
613+
ksort($links);
614+
return $links;
615+
}
581616
}

app/site/controllers/Admin/Blocks.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ protected function getObjectIdQueryParam(): string
121121
return 'block_id';
122122
}
123123

124+
/**
125+
* {@inheritdocs}
126+
*
127+
* @return array|null
128+
*/
129+
public Function getAdminPageLink() : array|null
130+
{
131+
return [
132+
'permission_name' => $this->getAccessPermission(),
133+
'route_name' => 'admin.blocks',
134+
'icon' => 'box',
135+
'text' => 'Blocks',
136+
'section' => 'cms',
137+
];
138+
}
139+
124140
/**
125141
* {@inheritdocs}
126142
*

app/site/controllers/Admin/Config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ protected function getObjectIdQueryParam(): string
6666
return 'config_id';
6767
}
6868

69+
/**
70+
* {@inheritdocs}
71+
*
72+
* @return array|null
73+
*/
74+
public Function getAdminPageLink() : array|null
75+
{
76+
return [
77+
'permission_name' => $this->getAccessPermission(),
78+
'route_name' => 'admin.config',
79+
'icon' => 'sliders',
80+
'text' => 'Config',
81+
'section' => 'system',
82+
];
83+
}
84+
6985
/**
7086
* {@inheritdocs}
7187
*

app/site/controllers/Admin/ContactForms.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ protected function getObjectIdQueryParam(): string
139139
return 'contact_id';
140140
}
141141

142+
/**
143+
* {@inheritdocs}
144+
*
145+
* @return array|null
146+
*/
147+
public Function getAdminPageLink() : array|null
148+
{
149+
return [
150+
'permission_name' => $this->getAccessPermission(),
151+
'route_name' => 'admin.contactforms',
152+
'icon' => 'file-text',
153+
'text' => 'Contact Forms',
154+
'section' => 'site',
155+
];
156+
}
157+
142158
/**
143159
* {@inheritdocs}
144160
*

app/site/controllers/Admin/Cron.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ protected function getObjectIdQueryParam(): string
140140
return 'task_id';
141141
}
142142

143+
/**
144+
* {@inheritdocs}
145+
*
146+
* @return array|null
147+
*/
148+
public Function getAdminPageLink() : array|null
149+
{
150+
return [
151+
'permission_name' => $this->getAccessPermission(),
152+
'route_name' => 'admin.cron',
153+
'icon' => 'watch',
154+
'text' => 'Cron Tasks',
155+
'section' => 'system',
156+
];
157+
}
158+
143159
/**
144160
* {@inheritdocs}
145161
*

app/site/controllers/Admin/Dashboard.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ protected function getAccessPermission(): string
5252
return 'administer_site';
5353
}
5454

55+
/**
56+
* {@inheritdocs}
57+
*
58+
* @return array|null
59+
*/
60+
public Function getAdminPageLink() : array|null
61+
{
62+
return [
63+
'permission_name' => '',
64+
'route_name' => 'admin.dashboard',
65+
'icon' => 'home',
66+
'text' => 'Dashboard',
67+
'section' => '',
68+
];
69+
}
70+
5571
/**
5672
* {@inheritdocs}
5773
*

app/site/controllers/Admin/Languages.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ protected function getObjectIdQueryParam(): string
6666
return 'language_id';
6767
}
6868

69+
/**
70+
* {@inheritdocs}
71+
*
72+
* @return array|null
73+
*/
74+
public Function getAdminPageLink() : array|null
75+
{
76+
return [
77+
'permission_name' => $this->getAccessPermission(),
78+
'route_name' => 'admin.languages',
79+
'icon' => 'flag',
80+
'text' => 'Languages',
81+
'section' => 'system',
82+
];
83+
}
84+
6985
/**
7086
* {@inheritdocs}
7187
*

app/site/controllers/Admin/Links.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ protected function getObjectIdQueryParam(): string
6868
return 'link_id';
6969
}
7070

71+
/**
72+
* {@inheritdocs}
73+
*
74+
* @return array|null
75+
*/
76+
public Function getAdminPageLink() : array|null
77+
{
78+
return [
79+
'permission_name' => $this->getAccessPermission(),
80+
'route_name' => 'admin.links',
81+
'icon' => 'link',
82+
'text' => 'Links',
83+
'section' => 'site',
84+
];
85+
}
86+
7187
/**
7288
* {@inheritdocs}
7389
*

0 commit comments

Comments
 (0)