Register the dashboard module sidebar via event handler

parent 72753ef4
<?php
namespace Modules\Dashboard\Sidebar;
namespace Modules\Dashboard\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Maatwebsite\Sidebar\SidebarExtender;
use Modules\Core\Events\BuildingSidebar;
use Modules\User\Contracts\Authentication;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterDashboardSidebar implements SidebarExtender
{
/**
* @var Authentication
......@@ -24,9 +26,13 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
$this->auth = $auth;
}
public function handle(BuildingSidebar $sidebar)
{
$sidebar->add($this->extendWith($sidebar->getMenu()));
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -3,8 +3,11 @@
namespace Modules\Dashboard\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Dashboard\Entities\Widget;
use Modules\Dashboard\Events\Handlers\RegisterDashboardSidebar;
use Modules\Dashboard\Repositories\Cache\CacheWidgetDecorator;
use Modules\Dashboard\Repositories\Eloquent\EloquentWidgetRepository;
use Modules\Dashboard\Repositories\WidgetRepository;
......@@ -12,7 +15,7 @@ use Modules\Workshop\Manager\StylistThemeManager;
class DashboardServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -36,6 +39,11 @@ class DashboardServiceProvider extends ServiceProvider
return new CacheWidgetDecorator($repository);
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('dashboard', RegisterDashboardSidebar::class)
);
}
public function boot(StylistThemeManager $theme)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment