|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use Laracasts\Presenter\Presenter; |
|
6
|
|
|
use Yajra\CMS\Contracts\UrlGenerator; |
|
7
|
|
|
|
|
8
|
|
|
class MenuPresenter extends Presenter |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Link href target window. |
|
12
|
|
|
* |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
public function target() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->entity->target == 0 ? '_self' : '_blank'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Indented title against depth. |
|
22
|
|
|
* |
|
23
|
|
|
* @param int $start |
|
24
|
|
|
* @param string $symbol |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
public function indentedTitle($start = 1, $symbol = '— ') |
|
28
|
|
|
{ |
|
29
|
|
|
$repeat = $this->entity->depth - $start; |
|
30
|
|
|
|
|
31
|
|
|
return str_repeat($symbol, $repeat >= 0 ? $repeat : 0) . ' ' . $this->entity->title; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Generate menu url depending on type the menu. |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public function url() |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var \Yajra\CMS\Repositories\Extension\Repository $repository */ |
|
42
|
|
|
$repository = app('extensions'); |
|
43
|
|
|
/** @var \Yajra\CMS\Entities\Extension $extension */ |
|
44
|
|
|
$extension = $repository->findOrFail($this->entity->extension_id); |
|
45
|
|
|
$class = $extension->param('class'); |
|
46
|
|
|
if (class_exists($class)) { |
|
47
|
|
|
$entity = app($class)->findOrNew($this->entity->param('id')); |
|
48
|
|
|
if ($entity instanceof UrlGenerator) { |
|
49
|
|
|
if (! $entity->exists) { |
|
|
|
|
|
|
50
|
|
|
return '#'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $entity->getUrl($this->entity->param('data')); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return url($this->entity->url); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get menu link custom style. |
|
62
|
|
|
* |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
*/ |
|
65
|
|
|
public function linkStyle() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->entity->param('link_style'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get menu link title. |
|
72
|
|
|
* |
|
73
|
|
|
* @return mixed |
|
74
|
|
|
*/ |
|
75
|
|
|
public function linkTitle() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->entity->param('link_title') ? $this->entity->param('link_title') : $this->entity->title; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: