-
Notifications
You must be signed in to change notification settings - Fork 554
/
BladePartial.php
56 lines (45 loc) · 1.17 KB
/
BladePartial.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace A17\Twill\Services\Forms;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\View as ViewFacade;
class BladePartial
{
protected function __construct(
protected ?string $view = null,
protected ?array $params = [],
) {
}
public static function make(): self
{
return new self();
}
public function view(string $view): static
{
$this->view = $view;
return $this;
}
public function withAdditionalParams(array $params = []): static
{
$this->params = $params;
return $this;
}
public function render(): ?View
{
if (! $this->view) {
return null;
}
$form = ViewFacade::shared('form');
return ViewFacade::make(
$this->view,
array_merge(
[
'item' => $form['item'] ?? null,
'form_fields' => $form['form_fields'] ?? [],
'formModuleName' => $form['moduleName'] ?? null,
'routePrefix' => $form['routePrefix'] ?? null,
],
$this->params
)
);
}
}