Skip to content

Commit bba81aa

Browse files
committed
wip: add AdminSidebar helper code
1 parent 3659af0 commit bba81aa

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"php": "^8.1",
2020
"illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0",
2121
"javaabu/helpers": "^1.61",
22-
"javaabu/translatable": "^1.1"
22+
"javaabu/translatable": "^1.1",
23+
"javaabu/menu-builder": "^1.6"
2324
},
2425
"require-dev": {
2526
"laravel/pint": "^1.14",

src/Cms.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
use Illuminate\Support\Facades\Route;
66
use Illuminate\Support\Str;
7+
use Javaabu\Cms\Enums\PostTypeFeatures;
78
use Javaabu\Cms\Http\Controllers\PostsController;
89
use Javaabu\Cms\Http\Controllers\Admin\PostsController as AdminPostsController;
910
use Javaabu\Cms\Models\CategoryType;
11+
use Javaabu\Cms\Models\Post;
1012
use Javaabu\Cms\Models\PostType;
13+
use Javaabu\MenuBuilder\Menu\MenuItem;
1114
use Javaabu\Translatable\Facades\Languages;
1215

1316
class Cms {
@@ -112,4 +115,38 @@ public function registerTranslatableAdminRoutes()
112115
$this->registerAdminRoutes();
113116
});
114117
}
118+
119+
public function addToSidebar($menus)
120+
{
121+
$all_post_types = PostType::all();
122+
123+
foreach ($all_post_types as $post_type) {
124+
$name = Str::title($post_type->name_en);
125+
$children = [
126+
MenuItem::make($name)
127+
->can('view_' . $post_type->permission_slug)
128+
->active(optional(request()->route('post_type'))->slug == $post_type->slug)
129+
->url(translate_route('admin.posts.index', $post_type->slug))
130+
->icon('zmdi-' . $post_type->icon)
131+
->count(Post::query()->userVisibleForPostType($post_type)->postType($post_type->slug)->pending()),
132+
];
133+
134+
if ($post_type->hasFeature(PostTypeFeatures::CATEGORIES)) {
135+
$children[] = MenuItem::make(_d(':name Categories', ['name' => Str::singular($name)]))
136+
->can('view_' . Str::singular($post_type->permission_slug) . '_categories')
137+
->url(translate_route('admin.categories.index', Str::singular($post_type->slug) . '-categories'))
138+
->active(optional(request()->route('category_type'))->slug == Str::singular($post_type->slug) . '-categories');
139+
140+
$menus[] =
141+
MenuItem::make($name)
142+
->icon('zmdi-' . $post_type->icon)
143+
->can('view_' . $post_type->permission_slug)
144+
->children($children);
145+
} else {
146+
$menus = array_merge($menus, $children);
147+
}
148+
}
149+
150+
return $menus;
151+
}
115152
}

0 commit comments

Comments
 (0)