|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Modules\Tag\Blade; |
|
4
|
|
|
|
|
5
|
|
|
use Modules\Tag\Contracts\TaggableInterface; |
|
6
|
|
|
use Modules\Tag\Repositories\TagRepository; |
|
7
|
|
|
|
|
8
|
|
|
class TagWidget |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var TagRepository |
|
12
|
|
|
*/ |
|
13
|
|
|
private $tag; |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $namespace; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var TaggableInterface|null |
|
20
|
|
|
*/ |
|
21
|
|
|
private $entity; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string|null |
|
24
|
|
|
*/ |
|
25
|
|
|
private $view; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string|null |
|
28
|
|
|
*/ |
|
29
|
|
|
private $name; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(TagRepository $tag) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->tag = $tag; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param $arguments |
|
38
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
39
|
|
|
*/ |
|
40
|
|
|
public function show($arguments) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->extractArguments($arguments); |
|
43
|
|
|
|
|
44
|
|
|
$view = $this->view ?: 'tag::admin.fields.tags'; |
|
45
|
|
|
|
|
46
|
|
|
$name = $this->name ?: 'Tags'; |
|
47
|
|
|
|
|
48
|
|
|
$availableTags = $this->tag->allForNamespace($this->namespace); |
|
49
|
|
|
|
|
50
|
|
|
$tags = $this->getTags(); |
|
51
|
|
|
|
|
52
|
|
|
return view($view, compact('availableTags', 'tags', 'name')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Extract the possible arguments as class properties |
|
57
|
|
|
* @param array $arguments |
|
58
|
|
|
*/ |
|
59
|
|
|
private function extractArguments(array $arguments) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->namespace = array_get($arguments, 0); |
|
62
|
|
|
$this->entity = array_get($arguments, 1); |
|
63
|
|
|
$this->view = array_get($arguments, 2); |
|
64
|
|
|
$this->name = array_get($arguments, 3); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the available tags, if an entity is available from that |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
private function getTags() |
|
72
|
|
|
{ |
|
73
|
|
|
if ($this->entity === null) { |
|
74
|
|
|
return request()->old('tags', []); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return request()->old('tags', $this->entity->tags->pluck('slug')->toArray()); |
|
|
|
|
|
|
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: