develop
HerrHase 3 years ago
parent f7e411f865
commit ca1fd41498

@ -117,3 +117,29 @@ function assetsUrl(string $id, array $options = NULL)
return $_ENV['DIRECTUS_API_URL'].'/assets/'.$id.$query;
}
/**
*
*
*
*/
function isCurrentPage($slug, $class = 'current')
{
// parse current url
$url = parse_url($_SERVER['REQUEST_URI']);
// getting path, remove first "/""
$path = ltrim($url['path'], '/');
// parse empty in NULL
// @TODO bad solution, check for using parent
if (empty($path)) {
$path = NULL;
}
if ($path !== $slug) {
$class = NULL;
}
return $class;
}

@ -25,7 +25,7 @@ class MenuRepository extends RepositoryAbstract
* @param string $slug
* @return array
*/
public function findOneByName($name)
public function findByName($name)
{
$results = $this->queryBuilder
->fields([
@ -42,14 +42,35 @@ class MenuRepository extends RepositoryAbstract
->aliases('page[status]', 'page_status')
->aliases('page[slug]', 'page_slug')
->filter([
'page' => [
'status' => 'published'
],
'menus' => [
'menus_id' => [
'name' => $name,
'status' => 'published'
]
'_or' => [
[
'_and' => [
[ 'page' => [
'id' => [
'_null' => 'true'
]
]],
[ 'menus' => [
'menus_id' => [
'name' => $name,
'status' => 'published'
]
]]
]
],
[
'_and' => [
[ 'page' => [
'status' => 'published'
]],
[ 'menus' => [
'menus_id' => [
'name' => $name,
'status' => 'published'
]
]]
]
],
]
])
->find();

@ -1,10 +1,12 @@
@inject('pageRepository', 'App\Repositories\PageRepository')
@inject('siteRepository', 'App\Repositories\SiteRepository')
@inject('menuRepository', 'App\Repositories\MenuRepository')
@inject('markdownHelper', 'App\Helpers\MarkdownHelper')
@php
$site = $siteRepository->findOne();
$menuItems = $menuRepository->findByName('test');
@endphp
<!DOCTYPE html>
@ -32,6 +34,7 @@
Super Gear Directus
<img src="{{ assetsUrl($site['data']['logo']) }}" />
</h1>
@include('partials.menu', [ 'menuItems' => $menuItems ])
</header>
<main class="site-main">

@ -0,0 +1,46 @@
@foreach($menuItems['data'] as $item)
@php
// class if url is same as page
$current = NULL;
// attribute target
$target = NULL;
// if page is not null
if ($item['page']) {
$title = $item['page']['title'];
$url = '/'.$item['page']['slug'];
// if page is current page
$current = isCurrentPage($item['page']['slug'], ' current');
// if title is set overwrite
if ($item['title']) {
$title = $item['title'];
}
// if page empty and only title and url is set
} elseif ($item['title'] && $item['url']) {
$title = $item['title'];
$url = $item['url'];
// if target set
if (isset($item['target'])) {
$target = 'target='.$item['target'];
if ($item['target'] === '_blank') {
$target .= ' rel=noreferrer';
}
}
} else {
continue;
}
@endphp
<a class="tabs__item{{ $current }}" {{ $target }} href="{{ $url }}">
{{ $title }}
</a>
@endforeach
Loading…
Cancel
Save