Register the dashboard module sidebar via event handler

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