2023-06-11 12:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Menu\Admin;
|
|
|
|
|
|
|
|
use Modules\Admin\Ui\Tab;
|
|
|
|
use Modules\Admin\Ui\Tabs;
|
|
|
|
use Modules\Page\Entities\Page;
|
|
|
|
use Modules\Menu\Entities\MenuItem;
|
|
|
|
use Modules\Category\Entities\Category;
|
|
|
|
|
|
|
|
class MenuItemTabs extends Tabs
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Make new tabs with groups.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function make()
|
|
|
|
{
|
|
|
|
$this->group('menu_item_information', trans('menu::menu_items.tabs.group.menu_item_information'))
|
|
|
|
->active()
|
|
|
|
->add($this->general())
|
|
|
|
->add($this->image());
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function general()
|
|
|
|
{
|
|
|
|
return tap(new Tab('general', trans('menu::menu_items.tabs.general')), function (Tab $tab) {
|
|
|
|
$tab->active();
|
|
|
|
$tab->weight(5);
|
|
|
|
$tab->view('menu::admin.menu_items.tabs.general', [
|
|
|
|
'categories' => $this->categories(),
|
|
|
|
'pages' => $this->pages(),
|
|
|
|
'parentMenuItems' => $this->parentMenuItems(),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function categories()
|
|
|
|
{
|
|
|
|
return Category::where('parent_id', null)->get()->sortBy('name')->pluck('name', 'id')
|
|
|
|
->prepend(trans('menu::menu_items.form.select_category'), '');
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function pages()
|
|
|
|
{
|
|
|
|
return Page::all()->sortBy('name')->pluck('name', 'id')
|
|
|
|
->prepend(trans('menu::menu_items.form.select_page'), '');
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function parentMenuItems()
|
|
|
|
{
|
|
|
|
$parentMenuItems = ['' => trans('menu::menu_items.form.select_parent')];
|
|
|
|
|
|
|
|
return $parentMenuItems += MenuItem::parents(request('menuId'), request('id'));
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function image()
|
|
|
|
{
|
|
|
|
return tap(new Tab('image', trans('menu::menu_items.tabs.image')), function (Tab $tab) {
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!auth()->user()->hasAccess('admin.media.index')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tab->weight(10);
|
|
|
|
$tab->view('menu::admin.menu_items.tabs.image');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|