FEATURE: make top menu extendable
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
namespace App\CMS\Handlers;
|
namespace App\CMS\Handlers;
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\BaseModuleHandler;
|
use App\CMS\Contracts\Modules\BaseModuleHandler;
|
||||||
use App\CMS\Enumerations\TemplatePathsHumanReadableRootOnly;
|
|
||||||
use App\CMS\Enumerations\WidgetTypes;
|
use App\CMS\Enumerations\WidgetTypes;
|
||||||
use App\CMS\Repositories\Module;
|
use App\CMS\Repositories\Module;
|
||||||
use App\Models\ActionLog\ActionLog;
|
use App\Models\ActionLog\ActionLog;
|
||||||
@@ -14,6 +13,7 @@ use App\Models\Templates\Template;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Widgets\Widget;
|
use App\Models\Widgets\Widget;
|
||||||
use App\Models\Widgets\WidgetArea;
|
use App\Models\Widgets\WidgetArea;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
abstract class BaseHandler implements BaseModuleHandler
|
abstract class BaseHandler implements BaseModuleHandler
|
||||||
{
|
{
|
||||||
@@ -125,6 +125,26 @@ abstract class BaseHandler implements BaseModuleHandler
|
|||||||
}, 10000, ['icon' => 'fa fa-fw fa-gears']);
|
}, 10000, ['icon' => 'fa fa-fw fa-gears']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
\Menu::create('topMenu', function ($menu) use ($user) {
|
||||||
|
if (count(LaravelLocalization::getSupportedLocales()) > 1) {
|
||||||
|
$menu->dropdown(trans(LaravelLocalization::getCurrentLocaleName()), function ($menu) use ($user) {
|
||||||
|
foreach (LaravelLocalization::getSupportedLocales() as $localeCode => $properties) {
|
||||||
|
$menu->url(LaravelLocalization::getLocalizedURL($localeCode), $properties['native']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->can('manage', Content::class)) {
|
||||||
|
$menu->route('page.index', '', [], 10, [
|
||||||
|
'icon' => 'fa fa-fw fa-globe',
|
||||||
|
'title' => trans('common.goToWeb'),
|
||||||
|
'target' => '_blank',
|
||||||
|
'data-toggle' => 'tooltip',
|
||||||
|
'data-placement' => 'left'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// create menu with user profile
|
// create menu with user profile
|
||||||
\Menu::create('profileMenu', function ($menu) use ($user) {
|
\Menu::create('profileMenu', function ($menu) use ($user) {
|
||||||
$menu->route('users.detail', trans('admin/userManagement.profile'), ['user' => $user], 10, ['icon' => 'fa fa-fw fa-user icon']);
|
$menu->route('users.detail', trans('admin/userManagement.profile'), ['user' => $user], 10, ['icon' => 'fa fa-fw fa-user icon']);
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\MenuPresenters;
|
|
||||||
|
|
||||||
use Nwidart\Menus\MenuItem;
|
|
||||||
use Nwidart\Menus\Presenters\Presenter;
|
|
||||||
|
|
||||||
class FoundationDrilldownMenuPresenter extends Presenter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getOpenTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '<ul class="vertical menu" data-drilldown>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getCloseTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '</ul>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithoutDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getActiveState(MenuItem $item)
|
|
||||||
{
|
|
||||||
$active = ' class="active"';
|
|
||||||
|
|
||||||
if (empty($item->getChilds())) {
|
|
||||||
// for direct menu input return if page is active
|
|
||||||
return \Request::is($item->getRequest()) ? $active : null;
|
|
||||||
} else {
|
|
||||||
// on nested menu inputs loop over children and in case any of them is active, mark active also root level
|
|
||||||
foreach ($item->getChilds() as $child) {
|
|
||||||
if ($this->getActiveState($child)) {
|
|
||||||
return $active;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getDividerWrapper()
|
|
||||||
{
|
|
||||||
return '<li class="divider"></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiLevelDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return $this->getMenuWithDropDownWrapper($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithDropDownWrapper($item)
|
|
||||||
{
|
|
||||||
$active = $this->getActiveState($item);
|
|
||||||
|
|
||||||
return '<li>
|
|
||||||
<a ' . $active . ' href="#">' . $item->getIcon() . ' ' . $item->title . '</a>
|
|
||||||
<ul class="vertical menu">
|
|
||||||
' . $this->getChildMenuItems($item) . '
|
|
||||||
</ul>
|
|
||||||
</li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\MenuPresenters;
|
|
||||||
|
|
||||||
use Nwidart\Menus\Presenters\Presenter;
|
|
||||||
|
|
||||||
class FoundationDropdownMenuPresenter extends Presenter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getOpenTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '<ul class="vertical dropdown menu" data-dropdown-menu>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getCloseTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '</ul>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithoutDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
$link = '<a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a>';
|
|
||||||
return '<li' . $this->getActiveState($item) . '>' . $link . '</li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getActiveState($item)
|
|
||||||
{
|
|
||||||
return \Request::is($item->getRequest()) || $item->hasActiveOnChild ? ' class="active"' : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getDividerWrapper()
|
|
||||||
{
|
|
||||||
return '<li class="divider"></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithDropDownWrapper($item)
|
|
||||||
{
|
|
||||||
return '<li>
|
|
||||||
<a href="#">' . $item->getIcon() . ' ' . $item->title . '</a>
|
|
||||||
<ul class="vertical menu">
|
|
||||||
' . $this->getChildMenuItems($item) . '
|
|
||||||
</ul>
|
|
||||||
</li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\MenuPresenters;
|
|
||||||
|
|
||||||
class FoundationInitializedDropdownMenuPresenter extends FoundationDropdownMenuPresenter
|
|
||||||
{
|
|
||||||
public function getOpenTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '<ul class="menu">' . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\CMS\MenuPresenters;
|
||||||
|
|
||||||
|
use Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter;
|
||||||
|
|
||||||
|
class TopMenuPresenter extends NavbarPresenter {
|
||||||
|
public function getOpenTagWrapper()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCloseTagWrapper()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-5
@@ -3,11 +3,9 @@
|
|||||||
return [
|
return [
|
||||||
|
|
||||||
'styles' => [
|
'styles' => [
|
||||||
'foundation-drilldown' => App\CMS\MenuPresenters\FoundationDrilldownMenuPresenter::class,
|
'metismenu' => App\CMS\MenuPresenters\MetismenuPresenter::class,
|
||||||
'foundation-dropdown' => App\CMS\MenuPresenters\FoundationDropdownMenuPresenter::class,
|
'profile-menu' => App\CMS\MenuPresenters\ProfileMenuPresenter::class,
|
||||||
'foundation-dropdown-initialized' => App\CMS\MenuPresenters\FoundationInitializedDropdownMenuPresenter::class,
|
'top-menu' => \App\CMS\MenuPresenters\TopMenuPresenter::class
|
||||||
'metismenu' => App\CMS\MenuPresenters\MetismenuPresenter::class,
|
|
||||||
'profile-menu' => App\CMS\MenuPresenters\ProfileMenuPresenter::class,
|
|
||||||
],
|
],
|
||||||
'ordering' => true,
|
'ordering' => true,
|
||||||
|
|
||||||
|
|||||||
+12
@@ -427,3 +427,15 @@ img {
|
|||||||
padding-left: 35px;
|
padding-left: 35px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-profile .dropdown-menu > li {
|
||||||
|
width: 100%;
|
||||||
|
padding: 3px 1.5rem;
|
||||||
|
clear: both;
|
||||||
|
font-weight: normal;
|
||||||
|
color: #373a3c;
|
||||||
|
text-align: inherit;
|
||||||
|
white-space: nowrap;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,29 +22,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="header-block header-block-nav">
|
<div class="header-block header-block-nav">
|
||||||
<ul class="nav-profile">
|
|
||||||
@if(count(LaravelLocalization::getSupportedLocales()) > 1)
|
|
||||||
<li class="profile dropdown">
|
|
||||||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button"
|
|
||||||
aria-haspopup="true" aria-expanded="false">
|
|
||||||
@lang(LaravelLocalization::getCurrentLocaleName())
|
|
||||||
</a>
|
|
||||||
<div class="dropdown-menu">
|
|
||||||
@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
|
|
||||||
<a hreflang="{{$localeCode}}"
|
|
||||||
href="{{LaravelLocalization::getLocalizedURL($localeCode) }}"
|
|
||||||
class="dropdown-item">
|
|
||||||
{{ $properties['native'] }}
|
|
||||||
</a>
|
|
||||||
@endforeach
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<li class="profile">
|
|
||||||
<a href="{{route('page.index')}}" target="_blank" class="nav-link" data-toggle="tooltip"
|
<ul class="nav-profile">
|
||||||
data-placement="bottom" title="@lang('common.goToWeb')"><i class="fa fa-fw fa-globe"></i></a>
|
|
||||||
</li>
|
{!! Menu::render('topMenu', 'top-menu') !!}
|
||||||
|
|
||||||
|
|
||||||
<li class="profile dropdown">
|
<li class="profile dropdown">
|
||||||
|
|||||||
Reference in New Issue
Block a user