|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services\Navigation\Breadcrumbs; |
|
4
|
|
|
|
|
5
|
|
|
use Breadcrumbs as BreadCrumbsManager; |
|
6
|
|
|
use DaveJamesMiller\Breadcrumbs\Manager; |
|
7
|
|
|
|
|
8
|
|
|
class Breadcrumbs |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var \DaveJamesMiller\Breadcrumbs\Manager |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $manager; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $modules = [ |
|
19
|
|
|
'article' => 'articles', |
|
20
|
|
|
'newsItem' => 'newsItems', |
|
21
|
|
|
'person' => 'people', |
|
22
|
|
|
'tag' => 'tags', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param \DaveJamesMiller\Breadcrumbs\Manager $manager |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(Manager $manager) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->manager = $manager; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function register() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->registerFragmentBreadcrumbs(); |
|
36
|
|
|
$this->registerUserBreadcrumbs(); |
|
37
|
|
|
|
|
38
|
|
|
foreach ($this->modules as $singular => $plural) { |
|
39
|
|
|
$this->module($singular, $plural); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function registerFragmentBreadcrumbs() |
|
44
|
|
|
{ |
|
45
|
|
|
BreadCrumbsManager::register('fragments', function ($breadcrumbs) { |
|
46
|
|
|
$breadcrumbs->push(fragment('back.fragments.title'), action('Back\FragmentController@index')); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
BreadCrumbsManager::register('fragmentDetail', function ($breadcrumbs, $string) { |
|
50
|
|
|
$breadcrumbs->parent('fragments'); |
|
51
|
|
|
$breadcrumbs->push($string->name, action('Back\FragmentController@edit', $string->id)); |
|
52
|
|
|
}); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function registerUserBreadcrumbs() |
|
56
|
|
|
{ |
|
57
|
|
|
BreadCrumbsManager::register('backUserListBack', function ($breadcrumbs) { |
|
58
|
|
|
$breadcrumbs->push(fragment('back.backUsers.title'), action('Back\BackUserController@index')); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
BreadCrumbsManager::register('newBackUserBack', function ($breadcrumbs) { |
|
62
|
|
|
$breadcrumbs->parent('backUserListBack'); |
|
63
|
|
|
$breadcrumbs->push(fragment('back.backUsers.new'), action('Back\BackUserController@create')); |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
BreadCrumbsManager::register('editBackUserBack', function ($breadcrumbs, $user) { |
|
67
|
|
|
$breadcrumbs->parent('backUserListBack', $user); |
|
68
|
|
|
$breadcrumbs->push($user->present()->fullName, action('Back\BackUserController@edit', $user->id)); |
|
69
|
|
|
}); |
|
70
|
|
|
|
|
71
|
|
|
BreadCrumbsManager::register('frontUserListBack', function ($breadcrumbs) { |
|
72
|
|
|
$breadcrumbs->push(fragment('back.frontUsers.title'), action('Back\FrontUserController@index')); |
|
73
|
|
|
}); |
|
74
|
|
|
|
|
75
|
|
|
BreadCrumbsManager::register('newFrontUserBack', function ($breadcrumbs) { |
|
76
|
|
|
$breadcrumbs->parent('frontUserListBack'); |
|
77
|
|
|
$breadcrumbs->push(fragment('back.frontUsers.new'), action('Back\FrontUserController@create')); |
|
78
|
|
|
}); |
|
79
|
|
|
|
|
80
|
|
|
BreadCrumbsManager::register('editFrontUserBack', function ($breadcrumbs, $user) { |
|
81
|
|
|
$breadcrumbs->parent('frontUserListBack', $user); |
|
82
|
|
|
$breadcrumbs->push($user->present()->fullName, action('Back\FrontUserController@edit', $user->id)); |
|
83
|
|
|
}); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $singular |
|
88
|
|
|
* @param string $plural |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function module($singular, $plural) |
|
91
|
|
|
{ |
|
92
|
|
|
$ucname = ucfirst($singular); |
|
93
|
|
|
|
|
94
|
|
|
BreadCrumbsManager::register( |
|
95
|
|
|
"{$singular}ListBack", |
|
96
|
|
|
function ($breadcrumbs) use ($ucname, $plural) { |
|
97
|
|
|
$breadcrumbs->push( |
|
98
|
|
|
fragment("back.{$plural}.title"), |
|
99
|
|
|
action("Back\\{$ucname}Controller@index") |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
BreadCrumbsManager::register( |
|
105
|
|
|
"{$singular}Back", |
|
106
|
|
|
function ($breadcrumbs, $model) use ($singular, $ucname, $plural) { |
|
107
|
|
|
$breadcrumbs->parent("{$singular}ListBack"); |
|
108
|
|
|
|
|
109
|
|
|
$breadcrumbs->push( |
|
110
|
|
|
$model->isDraft() ? fragment("back.{$plural}.new") : |
|
111
|
|
|
(isset($model->name) ? $model->name : ucfirst(fragment('back.change'))), |
|
112
|
|
|
action("Back\\{$ucname}Controller@create") |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|