1 | <?php |
||||
2 | |||||
3 | namespace Arbory\Base\Admin\Form\Fields\Renderer\Nested; |
||||
4 | |||||
5 | use Arbory\Base\Html\Html; |
||||
6 | use Arbory\Base\Admin\Panels\Panel; |
||||
7 | use Arbory\Base\Admin\Form\FieldSet; |
||||
8 | use Arbory\Base\Admin\Widgets\Button; |
||||
9 | use Arbory\Base\Html\Elements\Content; |
||||
10 | use Arbory\Base\Html\Elements\Element; |
||||
11 | use Arbory\Base\Admin\Form\Fields\FieldInterface; |
||||
12 | use Arbory\Base\Admin\Form\Fields\Concerns\HasRenderOptions; |
||||
13 | |||||
14 | class PaneledItemRenderer implements ItemInterface |
||||
15 | { |
||||
16 | use HasRenderOptions; |
||||
17 | |||||
18 | public function __invoke(FieldInterface $field, FieldSet $fieldSet, $index = null, array $parameters = []) |
||||
19 | { |
||||
20 | $title = $parameters['title'] ?? ''; |
||||
21 | |||||
22 | $panel = new Panel(); |
||||
23 | $panel->setTitle($title); |
||||
24 | $panel->addClass('item type-association') |
||||
25 | ->addAttributes( |
||||
26 | [ |
||||
27 | 'data-title' => $title, |
||||
28 | 'data-name' => $field->getName(), |
||||
29 | 'data-index' => $index, |
||||
30 | ] |
||||
31 | ); |
||||
32 | |||||
33 | $content = new Content([ |
||||
34 | $fieldSet->render(), |
||||
35 | ]); |
||||
36 | |||||
37 | $this->addSortableNavigation($field, $panel); |
||||
38 | $this->addRemoveButton($field, $panel, $content, $fieldSet->getNamespace().'._destroy'); |
||||
39 | |||||
40 | $panel->setContent($content); |
||||
41 | |||||
42 | return $panel->render(); |
||||
43 | } |
||||
44 | |||||
45 | /** |
||||
46 | * @param FieldInterface $field |
||||
47 | * @param Panel $panel |
||||
48 | * @param Content $content |
||||
49 | * @param $name |
||||
50 | * @return Element|null |
||||
51 | * |
||||
52 | * @throws \Arbory\Base\Exceptions\BadMethodCallException |
||||
53 | */ |
||||
54 | protected function addRemoveButton(FieldInterface $field, Panel $panel, Content $content, $name) |
||||
55 | { |
||||
56 | if (! $field->canRemoveRelationItems()) { |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
57 | return; |
||||
58 | } |
||||
59 | |||||
60 | $button = Button::create() |
||||
61 | ->title(trans('arbory::fields.relation.remove')) |
||||
62 | ->type('button', 'only-icon danger remove-nested-item') |
||||
63 | ->withIcon('delete_outline') |
||||
64 | ->iconOnly(); |
||||
65 | |||||
66 | $input = Html::input() |
||||
67 | ->setType('hidden') |
||||
68 | ->setName($name) |
||||
69 | ->setValue('false') |
||||
70 | ->addClass('destroy'); |
||||
71 | |||||
72 | $panel->addButton($button); |
||||
73 | |||||
74 | $content->push($input); |
||||
75 | |||||
76 | return $content; |
||||
77 | } |
||||
78 | |||||
79 | /** |
||||
80 | * @param FieldInterface $field |
||||
81 | * @param Panel $panel |
||||
82 | * @return Element |
||||
83 | */ |
||||
84 | protected function addSortableNavigation(FieldInterface $field, Panel $panel) |
||||
85 | { |
||||
86 | if (! $field->canSortRelationItems()) { |
||||
0 ignored issues
–
show
The method
canSortRelationItems() does not exist on Arbory\Base\Admin\Form\Fields\FieldInterface . It seems like you code against a sub-type of Arbory\Base\Admin\Form\Fields\FieldInterface such as Arbory\Base\Admin\Form\Fields\HasMany or Arbory\Base\Admin\Form\Fields\Constructor .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
87 | return; |
||||
88 | } |
||||
89 | |||||
90 | $panel->addButton( |
||||
91 | Button::create() |
||||
92 | ->title(trans('arbory::fields.relation.moveDown')) |
||||
93 | ->type('button', 'only-icon secondary sortable-navigation move-down') |
||||
94 | ->withIcon('keyboard_arrow_down') |
||||
95 | ->iconOnly() |
||||
96 | ); |
||||
97 | |||||
98 | $panel->addButton( |
||||
99 | Button::create() |
||||
100 | ->title(trans('arbory::fields.relation.moveUp')) |
||||
101 | ->type('button', 'only-icon secondary sortable-navigation move-up') |
||||
102 | ->withIcon('keyboard_arrow_up') |
||||
103 | ->iconOnly() |
||||
104 | ); |
||||
105 | } |
||||
106 | } |
||||
107 |