FEATURE: add template to menu widget
This commit is contained in:
@@ -12,9 +12,10 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
class Menu implements WidgetRenderer
|
||||
{
|
||||
public static $template = null;
|
||||
|
||||
/**
|
||||
* Method used for displaying widget.
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param Widget $widget
|
||||
@@ -27,6 +28,11 @@ class Menu implements WidgetRenderer
|
||||
$links = (array)$settings->links;
|
||||
$pageIds = array_keys($links);
|
||||
|
||||
if (!self::$template) {
|
||||
throw new \Exception('neni nastavena sablona');
|
||||
return;
|
||||
}
|
||||
|
||||
// get pages
|
||||
$pages = WidgetMenu::selectContentPages($pageIds);
|
||||
|
||||
@@ -40,14 +46,15 @@ class Menu implements WidgetRenderer
|
||||
$parameters = Route::current()
|
||||
->parameters();
|
||||
|
||||
$code = '<ul class="menu ' . $widget->container_class . '"';
|
||||
// $code = '<ul class="menu ' . $widget->container_class . '"';
|
||||
|
||||
if ($widget->container_id) {
|
||||
$code .= ' id="' . e($widget->container_id) . '"';
|
||||
}
|
||||
// if ($widget->container_id) {
|
||||
// $code .= ' id="' . e($widget->container_id) . '"';
|
||||
// }
|
||||
|
||||
$code .= '>';
|
||||
// $code .= '>';
|
||||
|
||||
$menuItems = [];
|
||||
foreach ($links as $pageId => $link) {
|
||||
if (!isset($pages[$pageId])) {
|
||||
continue;
|
||||
@@ -57,16 +64,22 @@ class Menu implements WidgetRenderer
|
||||
$active = ($page->isHomepage && $routeName == 'page.index') || ($routeName == 'page.content' && isset($parameters['url']) && $parameters['url'] == $page->url);
|
||||
$route = $page->isHomepage ? route('page.index') : route('page.content', ['url' => $page->url]);
|
||||
|
||||
$code .= '<li';
|
||||
if ($active) {
|
||||
$code .= ' class="is-active active"';
|
||||
}
|
||||
$code .= '><a href="' . $route . '">' . e($page->title) . '</a></li>';
|
||||
$menuItems[] = compact('page', 'active', 'route');
|
||||
|
||||
// $code .= '<li';
|
||||
// if ($active) {
|
||||
// $code .= ' class="is-active active"';
|
||||
}
|
||||
// $code .= '><a href="' . $route . '">' . e($page->title) . '</a></li>';
|
||||
// }
|
||||
|
||||
$code .= "</ul>";
|
||||
// $code .= "</ul>";
|
||||
|
||||
return $code;
|
||||
return view(self::$template, [
|
||||
'containerClass' => $widget->container_class,
|
||||
'containerId' => $widget->container_id,
|
||||
'menuItems' => $menuItems
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user