Using a sidebar event listener for menu module

parent 7de37fc7
......@@ -6,6 +6,7 @@ versions:
- <code>FileWasUpdated</code> event
- <code>FileIsCreating</code> hookable event
- <code>FileIsUpdating</code> hookable event
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
<?php
namespace Modules\Menu\Sidebar;
namespace Modules\Menu\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterMenuSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -3,10 +3,13 @@
namespace Modules\Menu\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Menu\Blade\MenuDirective;
use Modules\Menu\Entities\Menu;
use Modules\Menu\Entities\Menuitem;
use Modules\Menu\Events\Handlers\RegisterMenuSidebar;
use Modules\Menu\Repositories\Cache\CacheMenuDecorator;
use Modules\Menu\Repositories\Cache\CacheMenuItemDecorator;
use Modules\Menu\Repositories\Eloquent\EloquentMenuItemRepository;
......@@ -19,7 +22,7 @@ use Nwidart\Menus\MenuItem as PingpongMenuItem;
class MenuServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -39,6 +42,11 @@ class MenuServiceProvider extends ServiceProvider
$this->app->bind('menu.menu.directive', function () {
return new MenuDirective();
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('media', RegisterMenuSidebar::class)
);
}
/**
......
......@@ -6,6 +6,7 @@ versions:
- Trigger event before a menu is updated (<code>MenuIsUpdating</code>) allow data to be changed
- Trigger event before a menu item is created (<code>MenuItemIsCreating</code>) allow data to be changed
- Trigger event before a menu item is updated (<code>MenuItemIsUpdating</code>) allow data to be changed
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
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