|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace A17\Twill\Http\ViewComposers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\View\View; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
|
|
9
|
|
|
class ActiveNavigation |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var Request |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $request; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param Request $request |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public function __construct(Request $request) |
|
20
|
|
|
{ |
|
21
|
1 |
|
$this->request = $request; |
|
22
|
1 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Binds data to the view. |
|
26
|
|
|
* |
|
27
|
|
|
* @param View $view |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function compose(View $view) |
|
31
|
|
|
{ |
|
32
|
1 |
|
if ($this->request->route()) { |
|
33
|
1 |
|
$routeName = $this->request->route()->getName(); |
|
34
|
|
|
|
|
35
|
1 |
|
$activeMenus = explode('.', $routeName); |
|
36
|
|
|
|
|
37
|
|
|
//starts at 1 because first segment of all back route name is 'admin' |
|
38
|
1 |
|
$view_active_variables['_global_active_navigation'] = $activeMenus[1]; |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
1 |
|
if (count($activeMenus) > 2) { |
|
41
|
|
|
$view_active_variables['_primary_active_navigation'] = $activeMenus[2]; |
|
42
|
1 |
|
} else if (count($this->request->route()->parameters()) > 0) { |
|
43
|
|
|
$view_active_variables['_primary_active_navigation'] = Arr::first($this->request->route()->parameters()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
if (count($activeMenus) > 3) { |
|
47
|
|
|
$view_active_variables['_secondary_active_navigation'] = $activeMenus[3] !== 'index' ? $activeMenus[3] : $activeMenus[2]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
$with = array_merge($view_active_variables, Arr::only($view->getData(), [ |
|
51
|
1 |
|
'_global_active_navigation', |
|
52
|
|
|
'_primary_active_navigation', |
|
53
|
|
|
'_secondary_active_navigation', |
|
54
|
|
|
])); |
|
55
|
|
|
|
|
56
|
1 |
|
$view->with($with); |
|
57
|
|
|
} |
|
58
|
1 |
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|