Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit cfffc1a

Browse files
committed
changes
- change `urlRoute()` to `routeUrl()` - change `urlRouteCheck()` to `isActiveRoute()` - check & get current page breadcrumb internally - clear all the cache on page update “due to issues with baum\node” - remove the redir to home if one of the bc is in diff locale as its not working correctly
1 parent a8c8d76 commit cfffc1a

File tree

7 files changed

+38
-50
lines changed

7 files changed

+38
-50
lines changed

src/Controllers/DummyController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace ctf0\SimpleMenu\Controllers;
44

5-
use ctf0\SimpleMenu\Facade\SimpleMenu;
65
use Illuminate\Support\Facades\Route;
6+
use ctf0\SimpleMenu\Facade\SimpleMenu;
77

88
class DummyController extends BaseController
99
{
1010
public function handle()
1111
{
1212
extract(SimpleMenu::getRouteData(Route::currentRouteName()));
1313

14-
return view("$this->templatePath.$template", compact('title', 'body', 'desc', 'breadCrumb'));
14+
return view("$this->templatePath.$template", compact('title', 'body', 'desc'));
1515
}
1616
}

src/Observers/PageObserver.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88

99
class PageObserver
1010
{
11-
use ClearCacheTrait;
12-
1311
/**
14-
* Listen to the User saving event.
12+
* Listen to the User saved event.
1513
*/
16-
public function saving(Page $page)
14+
public function saved(Page $page)
1715
{
1816
return $this->cleanData($page);
1917
}
2018

2119
/**
22-
* Listen to the User deleting event.
20+
* Listen to the User deleted event.
2321
*/
24-
public function deleting(Page $page)
22+
public function deleted(Page $page)
2523
{
2624
return $this->cleanData($page);
2725
}
@@ -44,16 +42,8 @@ protected function cleanData($page)
4442
// remove the route file
4543
File::delete(config('simpleMenu.routeListPath'));
4644

47-
// clear page cache
48-
$this->clearCache($route_name);
49-
$this->clearCache('_ancestors');
50-
$this->clearCache('_nests');
51-
52-
// clear menu cache
53-
foreach ($page->menus->pluck('name') as $menu) {
54-
$this->clearCache("{$menu}Menu");
55-
}
56-
57-
$this->clearPagesCache();
45+
// clear all cache
46+
// due to issues with baum\node
47+
Cache::flush();
5848
}
5949
}

src/Traits/NavigationTrait.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ public function getUrl($code)
2121
{
2222
$name = Route::currentRouteName();
2323

24-
// redir to '/' if current route ancestor is not found under current locale
25-
$bc = $this->getRouteData($name)['breadCrumb'];
26-
27-
if (isset($bs) && count($bc)) {
28-
if (!$this->searchForRoute($bc->pluck('route_name')->first(), $code)) {
29-
return LaravelLocalization::getLocalizedURL($code, url('/'), [], true);
30-
}
31-
}
32-
3324
// routeName is not saved in the db (ex.php artisan make:auth)
3425
// or only url
3526
$routesListFile = include $this->listFileDir;
@@ -61,6 +52,7 @@ public function getUrl($code)
6152
*/
6253
public function getRoute($crntRouteName, array $params = null)
6354
{
55+
// where route is available under one locale but not the other
6456
if (!Route::has($crntRouteName)) {
6557
return;
6658
}
@@ -98,12 +90,12 @@ public function getRoute($crntRouteName, array $params = null)
9890
*
9991
* @return [type] [description]
10092
*/
101-
public function urlRoute()
93+
public function routeUrl()
10294
{
10395
return $this->urlRoute;
10496
}
10597

106-
public function urlRouteCheck()
98+
public function isActiveRoute()
10799
{
108100
return request()->url() == $this->urlRoute;
109101
}
@@ -113,9 +105,14 @@ public function getRouteData($name)
113105
return cache($this->getCrntLocale() . "-$name");
114106
}
115107

116-
public function checkForBC($bc)
108+
public function getBC()
117109
{
118-
return count($bc) && $this->searchForRoute($bc->pluck('route_name')->first(), $this->getCrntLocale());
110+
$name = Route::currentRouteName();
111+
$bc = $this->getRouteData($name)['breadCrumb'];
112+
113+
if (isset($bc) && count($bc) && $this->searchForRoute($bc->pluck('route_name')->first(), $this->getCrntLocale())) {
114+
return $bc;
115+
}
119116
}
120117

121118
/**
@@ -126,14 +123,6 @@ public function checkForBC($bc)
126123
*
127124
* @return [type] [description]
128125
*/
129-
protected function searchForRoute($name, $code)
130-
{
131-
$routesListFile = include $this->listFileDir;
132-
133-
// check if we have a link according to that "routeName & code"
134-
return array_get($routesListFile, "$name.$code") ?? false;
135-
}
136-
137126
protected function routeLink($name, $code)
138127
{
139128
$searchCode = $this->searchForRoute($name, $code);
@@ -153,6 +142,14 @@ protected function routeLink($name, $code)
153142
return $searchCode;
154143
}
155144

145+
protected function searchForRoute($name, $code)
146+
{
147+
$routesListFile = include $this->listFileDir;
148+
149+
// check if we have a link according to that "routeName & code"
150+
return array_get($routesListFile, "$name.$code") ?? false;
151+
}
152+
156153
/**
157154
* render menu.
158155
*

src/resources/views/admin/bulma/pages/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<tr id="item-{{ $page->id }}">
3232
<td>
3333
@if (in_array(LaravelLocalization::getCurrentLocale(), $page->getTranslatedLocales('title')))
34-
<a href="{{ SimpleMenu::urlRoute() }}">{{ $page->title }}</a>
34+
<a href="{{ SimpleMenu::routeUrl() }}">{{ $page->title }}</a>
3535
@else
3636
{{ empty($page->title) ? collect($page->getTranslations('title'))->first() : $page->title }}
3737
@endif
@@ -90,4 +90,4 @@
9090
</table>
9191
</div>
9292
</index-comp>
93-
@stop
93+
@stop
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
@if (isset($breadCrumb) && SimpleMenu::checkForBC($breadCrumb))
1+
@if ($breadCrumb = SimpleMenu::getBC())
22
<nav class="breadcrumb">
33
<ul>
44
@foreach ($breadCrumb as $page)
5+
@break(!$page->title)
56
@include('SimpleMenu::menu.partials.r_params')
67

7-
<li class="{{ SimpleMenu::urlRouteCheck() ? 'is-active' : '' }}">
8-
<a href="{{ SimpleMenu::urlRoute() }}">
8+
<li class="{{ SimpleMenu::isActiveRoute() ? 'is-active' : '' }}">
9+
<a href="{{ SimpleMenu::routeUrl() }}">
910
{{ $page->title }}
1011
</a>
1112
</li>
1213
@endforeach
1314
</ul>
1415
</nav>
1516
<hr>
16-
@endif
17+
@endif

src/resources/views/menu/example.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
@include('SimpleMenu::menu.partials.r_params')
66

77
<li>
8-
<a href="{{ SimpleMenu::urlRoute() }}" class="{{ SimpleMenu::urlRouteCheck() ? 'is-active' : '' }}">{{ $page->title }}</a>
8+
<a href="{{ SimpleMenu::routeUrl() }}" class="{{ SimpleMenu::isActiveRoute() ? 'is-active' : '' }}">{{ $page->title }}</a>
99

1010
@if ($childs = $page->nests)
1111
@include('SimpleMenu::menu.partials.nested', ['items' => $childs])
1212
@endif
1313
</li>
1414
@endforeach
1515
</ul>
16-
@endif
16+
@endif

src/resources/views/menu/partials/nested.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
@include('SimpleMenu::menu.partials.r_params')
44

55
<li>
6-
<a href="{{ SimpleMenu::urlRoute() }}" class="{{ SimpleMenu::urlRouteCheck() ? 'is-active' : '' }}">{{ $page->title }}</a>
6+
<a href="{{ SimpleMenu::routeUrl() }}" class="{{ SimpleMenu::isActiveRoute() ? 'is-active' : '' }}">{{ $page->title }}</a>
77

88
@if ($childs = $page->nests)
99
@include('SimpleMenu::menu.partials.nested', ['items' => $childs])
1010
@endif
1111
</li>
1212
@endforeach
13-
</ul>
13+
</ul>

0 commit comments

Comments
 (0)