Skip to content

Commit

Permalink
fix #33
Browse files Browse the repository at this point in the history
Remove "laravolt.menu" binding
Use only "laravolt.menu.sidebar"
  • Loading branch information
uyab committed Feb 15, 2020
1 parent 6f3860b commit e858cb3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
19 changes: 4 additions & 15 deletions src/Platform/Providers/UiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Laravolt\Platform\Enums\Permission;
use Laravolt\Platform\Http\Middleware\FlashMiddleware;
use Laravolt\Platform\Services\Flash;
use Laravolt\Platform\Services\Menu;
Expand Down Expand Up @@ -35,25 +36,13 @@ public function register()
return new Menu();
});

$this->app->singleton(
'laravolt.menu',
function (Application $app) {
return app('laravolt.menu.sidebar')->make(
'sidebar',
function (Builder $menu) {
return $menu;
}
);
}
);

$this->bootConfig();

// We add default menu in register() method,
// to make sure it is always accessible by other providers.
$this->app['laravolt.menu']
->add('System')
->data('order', config('laravolt.ui.system_menu.order'));
app('laravolt.menu.sidebar')->register(function ($menu) {
$menu->add('System')->data('order', config('laravolt.ui.system_menu.order'));
});

$this->registerAssets();

Expand Down
8 changes: 7 additions & 1 deletion src/Platform/Services/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Laravolt\Platform\Services;

use Lavary\Menu\Builder;
use Lavary\Menu\Item;
use Lavary\Menu\Menu as BaseMenu;

Expand Down Expand Up @@ -44,7 +45,12 @@ public static function setActiveParent($children, $isActive, $active = 'active c

public function all()
{
$sidebar = $this->get('sidebar');
$sidebar = app('laravolt.menu.sidebar')->make(
'sidebar',
function (Builder $menu) {
return $menu;
}
);

foreach ($this->callbacks as $callback) {
call_user_func($callback, $sidebar);
Expand Down
27 changes: 16 additions & 11 deletions src/Platform/Services/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ public function make()

public function loadSection($name, $menu, $options = [])
{
$section = app('laravolt.menu')->add($name);
$this->setData($section, $options);

$this->addMenu($section, $menu);
app('laravolt.menu.sidebar')->register(function ($menu) use ($name, $options) {
$section = $menu->add($name);
$this->setData($section, $options);
$this->addMenu($section, $menu);
});
}

public function loadArray(array $menu)
{
foreach ($menu as $title => $option) {
$section = app('laravolt.menu')->add($title);
if (isset($option['menu'])) {
$this->addMenu($section, $option['menu']);
}
if (isset($option['data'])) {
$this->setData($section, $option['data']);
}

app('laravolt.menu.sidebar')->register(function ($menu) use ($title, $option) {
$section = $menu->add($title);
if (isset($option['menu'])) {
$this->addMenu($section, $option['menu']);
}
if (isset($option['data'])) {
$this->setData($section, $option['data']);
}
});

}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laravolt\Platform\Providers\EpicentrumServiceProvider;
use Laravolt\Platform\Providers\PlatformServiceProvider;
use Laravolt\Platform\Providers\UiServiceProvider;
use Lavary\Menu\ServiceProvider;

trait Bootstrap
{
Expand Down Expand Up @@ -46,6 +47,7 @@ protected function getEnvironmentSetUp($app)
protected function getPackageProviders($app)
{
return [
ServiceProvider::class,
AuthServiceProvider::class,
EpicentrumServiceProvider::class,
NoCaptchaServiceProvider::class,
Expand Down

0 comments on commit e858cb3

Please sign in to comment.