1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\View\Components; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Illuminate\View\Component; |
7
|
|
|
use Thinktomorrow\Chief\Fragments\Database\FragmentRepository; |
8
|
|
|
use Thinktomorrow\Chief\Fragments\FragmentsComponentRepository; |
9
|
|
|
use Thinktomorrow\Chief\Fragments\FragmentsOwner; |
10
|
|
|
use Thinktomorrow\Chief\Managers\Register\Registry; |
11
|
|
|
|
12
|
|
|
// Nested fragments component in sidebar (cannot use livewire for this) |
13
|
|
|
class Fragments extends Component |
14
|
|
|
{ |
15
|
|
|
public FragmentsOwner $owner; |
16
|
|
|
|
17
|
|
|
private FragmentsComponentRepository $repository; |
18
|
|
|
private Collection $fragments; |
19
|
|
|
private array $allowedFragments; |
20
|
|
|
private array $sharedFragments; |
21
|
|
|
|
22
|
|
|
public function __construct(FragmentsOwner $owner) |
23
|
|
|
{ |
24
|
|
|
$this->repository = new FragmentsComponentRepository(app(FragmentRepository::class), app(Registry::class), $owner); |
25
|
|
|
$this->owner = $owner; |
26
|
|
|
$this->load(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View |
31
|
|
|
*/ |
32
|
|
|
public function render() |
33
|
|
|
{ |
34
|
|
|
return view('chief-fragments::window', [ |
35
|
|
|
'fragments' => $this->fragments, |
36
|
|
|
'allowedFragments' => $this->allowedFragments, |
37
|
|
|
'sharedFragments' => $this->sharedFragments, |
38
|
|
|
'manager' => $this->repository->getManager(), |
39
|
|
|
'owner' => $this->owner, |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function load(): void |
44
|
|
|
{ |
45
|
|
|
$this->fragments = $this->repository->getFragments(); |
46
|
|
|
$this->allowedFragments = $this->repository->getAllowedFragments(); |
47
|
|
|
$this->sharedFragments = $this->repository->getSharedFragments(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|