Skip to content

Commit cde389d

Browse files
authored
Merge pull request exodusanto#23 from hubertnnn/master
Allow custom routes in administrator menu
2 parents a5bda96 + d22c823 commit cde389d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Frozennode/Administrator/Config/Factory.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class Factory {
6464
*/
6565
protected $pagePrefix = 'page.';
6666

67+
/**
68+
* The custom route menu prefix
69+
*
70+
* @var string
71+
*/
72+
protected $routePrefix = 'route.';
73+
6774
/**
6875
* The rules array
6976
*
@@ -124,7 +131,7 @@ public function make($name, $primary = false)
124131
$options = $this->searchMenu($name);
125132

126133
//return the config object if the file/array was found, or false if it wasn't
127-
$config = $options ? $this->getItemConfigObject($options) : ($this->type === 'page' ? true : false);
134+
$config = $options ? $this->getItemConfigObject($options) : (($this->type === 'page' || $this->type === 'route') ? true : false);
128135

129136
//set the primary config
130137
$this->config = $primary ? $config : $this->config;
@@ -176,6 +183,11 @@ public function parseType($name)
176183
{
177184
return $this->type = 'page';
178185
}
186+
//otherwise if the name is prefixed with the page prefix
187+
elseif (strpos($name, $this->routePrefix) === 0)
188+
{
189+
return $this->type = 'route';
190+
}
179191
//otherwise it's a model
180192
else
181193
{
@@ -242,6 +254,14 @@ public function getPagePrefix()
242254
return $this->pagePrefix;
243255
}
244256

257+
/**
258+
* Gets the prefix for the currently-searched item
259+
*/
260+
public function getRoutePrefix()
261+
{
262+
return $this->routePrefix;
263+
}
264+
245265
/**
246266
* Gets the prefix for the currently-searched item
247267
*/

src/viewComposers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
$view->menu = app('admin_menu')->getMenu();
5858
$view->settingsPrefix = app('admin_config_factory')->getSettingsPrefix();
5959
$view->pagePrefix = app('admin_config_factory')->getPagePrefix();
60+
$view->routePrefix = app('admin_config_factory')->getRoutePrefix();
6061
$view->configType = app()->bound('itemconfig') ? app('itemconfig')->getType() : false;
6162
});
6263

src/views/partials/menu_item.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
'item' => $subitem,
88
'key' => $k,
99
'settingsPrefix' => $settingsPrefix,
10-
'pagePrefix' => $pagePrefix
10+
'pagePrefix' => $pagePrefix,
11+
'routePrefix' => $routePrefix,
1112
))?>
1213
@endforeach
1314
</ul>
@@ -18,6 +19,8 @@
1819
<a href="{{route('admin_settings', array(substr($key, strlen($settingsPrefix)), false))}}">{{$item}}</a>
1920
@elseif (strpos($key, $pagePrefix) === 0)
2021
<a href="{{route('admin_page', array(substr($key, strlen($pagePrefix)), false))}}">{{$item}}</a>
22+
@elseif (strpos($key, $routePrefix) === 0)
23+
<a href="{{route(substr($key, strlen($routePrefix)), [], false)}}">{{$item}}</a>
2124
@else
2225
<a href="{{route('admin_index', array($key), false)}}">{{$item}}</a>
2326
@endif

0 commit comments

Comments
 (0)