IMPROVEMENT: Submenu Widget

This commit is contained in:
Tony Air 2019-12-12 23:04:57 +07:00
parent fdebf4abef
commit 5678bb0aee
5 changed files with 61 additions and 5 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace Site\Widgets;
use Sheadawson\Linkable\Forms\LinkField;
use Sheadawson\Linkable\Models\Link;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Widgets\Model\Widget;
if (!class_exists(Widget::class)) {
return;
}
class SubmenuWidget extends Widget
{
private static $title = 'Sub-Menu';
private static $cmsTitle = 'Sub-Menu';
private static $description = 'Shows sub menu.';
private static $icon = '<i class="icon font-icon-tree"></i>';
private static $table_name = 'SubmenuWidget';
public function getPage()
{
$area = $this->Parent();
return \Page::get()->filter('SideBarID', $area->ID)->first();
}
public function getSubmenu()
{
$page = $this->getPage();
$children = $page->Children();
$children = $children->count() ? $children : $page->Level(1)->Children();
return $children;
}
}

View File

@ -20,7 +20,7 @@
$Breadcrumbs
<% end_if %>
<% if $SideBarView && $SideBar.Widgets.Count %>
<% if $SideBarView && $SideBarView.Widgets.Count %>
<div class="$DefaultContainer">
<div class="row">
<div class="col-md-8">

View File

@ -0,0 +1,8 @@
<img src="$Image.Fill(432,324).URL" alt="$Title" />
<% if $Link %>
<% with $Link %>
<a href="$URL"<% if $OpenInNewWindow %> target="_blank"<% end_if %> class="stretched-link">
<span class="sr-only">$Up.Title</span>
</a>
<% end_with %>
<% end_if %>

View File

@ -0,0 +1,9 @@
<% if $Submenu %>
<nav>
<ul class="nav flex-column">
<% loop $Submenu %>
<% include NavItem %>
<% end_loop %>
</ul>
</nav>
<% end_if %>

View File

@ -27,8 +27,8 @@
],
"dependencies": {
"@a2nt/meta-lightbox": "^1.2.2",
"@a2nt/ss-bootstrap-ui-webpack-boilerplate": "^1.3.0",
"yarn": "^1.21.0"
"@a2nt/ss-bootstrap-ui-webpack-boilerplate": "^1.3.2",
"yarn": "^1.21.1"
},
"devDependencies": {
"@google/markerclusterer": "^1.0.3",
@ -55,7 +55,7 @@
"core-util-is": "^1.0.2",
"croppie": "^2.6.4",
"cross-env": "^5.2.1",
"css-loader": "^3.3.0",
"css-loader": "^3.3.1",
"eslint": "^4.18.1",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jquery": "^1.5.1",
@ -104,7 +104,7 @@
"smooth-scroll": "^14.2.1",
"style-loader": "^0.19.0",
"svg-url-loader": "^2.3.3",
"terser-webpack-plugin": "^2.2.2",
"terser-webpack-plugin": "^2.3.0",
"uglify-js": "git://github.com/mishoo/UglifyJS2.git#harmony-v2.8.22",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^0.6.2",