@@ -85,43 +85,58 @@ protected function getHeaderActions(): array
85
85
->icon ('heroicon-o-plus ' )
86
86
->color ('primary ' )
87
87
->form ($ this ->getMenuItemFormSchema ())
88
- ->action (function (array $ data ): void {
88
+ ->fillForm (function (array $ arguments ): array {
89
+ $ parentId = $ arguments ['parent_id ' ] ?? null ;
90
+ return [
91
+ 'parent_id ' => $ parentId ,
92
+ 'is_visible ' => true ,
93
+ 'target ' => '_self '
94
+ ];
95
+ })
96
+ ->action (function (array $ data , array $ arguments ): void {
97
+ // Merge parent_id from arguments into data
98
+ $ parentId = $ arguments ['parent_id ' ] ?? null ;
99
+ if ($ parentId ) {
100
+ $ data ['parent_id ' ] = $ parentId ;
101
+ }
89
102
$ this ->createMenuItem ($ data );
90
103
})
91
- ->modalHeading (flexiblePagesTrans ('menu_items.tree.add_item ' ))
104
+ ->modalHeading (function (array $ arguments ): string {
105
+ $ parentId = $ arguments ['parent_id ' ] ?? null ;
106
+ return $ parentId
107
+ ? flexiblePagesTrans ('menu_items.tree.add_child ' )
108
+ : flexiblePagesTrans ('menu_items.tree.add_item ' );
109
+ })
92
110
->modalSubmitActionLabel (__ ('Create ' ))
93
111
->modalWidth ('2xl ' )
94
112
->slideOver (),
95
113
];
96
114
}
97
115
98
- public function addMenuItem (? int $ parentId = null ): void
116
+ protected function getActions ( ): array
99
117
{
100
- $ this ->mountAction ('addMenuItem ' , ['parent_id ' => $ parentId ]);
118
+ return [
119
+ $ this ->editMenuItemAction (),
120
+ $ this ->deleteMenuItemAction (),
121
+ ];
101
122
}
102
123
103
- public function editMenuItem (int $ itemId ): void
104
- {
105
- $ item = $ this ->getMenuItemSecurely ($ itemId );
106
-
107
- if (! $ item ) {
108
- Notification::make ()
109
- ->title (flexiblePagesTrans ('menu_items.errors.item_not_found ' ))
110
- ->danger ()
111
- ->send ();
112
-
113
- return ;
114
- }
115
124
116
- $ this ->mountAction ('editMenuItem ' , ['item ' => $ item ]);
117
- }
118
125
119
126
public function editMenuItemAction (): Action
120
127
{
121
128
return Action::make ('editMenuItem ' )
122
129
->form ($ this ->getMenuItemFormSchema ())
123
130
->fillForm (function (array $ arguments ): array {
124
- $ item = $ arguments ['item ' ];
131
+ $ itemId = $ arguments ['itemId ' ] ?? null ;
132
+ if (!$ itemId ) {
133
+ return [];
134
+ }
135
+
136
+ $ item = $ this ->getMenuItemSecurely ($ itemId );
137
+ if (!$ item ) {
138
+ return [];
139
+ }
125
140
126
141
return [
127
142
'link_type ' => $ item ->link_type ,
@@ -136,15 +151,33 @@ public function editMenuItemAction(): Action
136
151
];
137
152
})
138
153
->action (function (array $ data , array $ arguments ): void {
139
- $ item = $ arguments ['item ' ];
140
- $ this ->updateMenuItem ($ item ->id , $ data );
154
+ $ itemId = $ arguments ['itemId ' ] ?? null ;
155
+ if ($ itemId ) {
156
+ $ this ->updateMenuItem ($ itemId , $ data );
157
+ }
141
158
})
142
159
->modalHeading (flexiblePagesTrans ('menu_items.tree.edit ' ))
143
160
->modalSubmitActionLabel (__ ('Update ' ))
144
161
->modalWidth ('2xl ' )
145
162
->slideOver ();
146
163
}
147
164
165
+ public function deleteMenuItemAction (): Action
166
+ {
167
+ return Action::make ('deleteMenuItem ' )
168
+ ->requiresConfirmation ()
169
+ ->modalHeading (flexiblePagesTrans ('menu_items.tree.delete_confirm_title ' ))
170
+ ->modalDescription (flexiblePagesTrans ('menu_items.tree.delete_confirm_text ' ))
171
+ ->modalSubmitActionLabel (flexiblePagesTrans ('menu_items.tree.delete ' ))
172
+ ->color ('danger ' )
173
+ ->action (function (array $ arguments ): void {
174
+ $ itemId = $ arguments ['itemId ' ] ?? null ;
175
+ if ($ itemId ) {
176
+ $ this ->deleteMenuItem ($ itemId );
177
+ }
178
+ });
179
+ }
180
+
148
181
protected function getMenuItemFormSchema (): array
149
182
{
150
183
return MenuItemForm::getSchema ();
@@ -718,7 +751,8 @@ public function updateMenuItem(int $itemId, array $data): void
718
751
719
752
protected function validateMenuItemData (array $ data ): void
720
753
{
721
- if (empty ($ data ['label ' ])) {
754
+ // Label is only required if use_model_title is false
755
+ if (empty ($ data ['label ' ]) && !($ data ['use_model_title ' ] ?? false )) {
722
756
throw new Exception (flexiblePagesTrans ('menu_items.form.label_lbl ' ).' is required ' );
723
757
}
724
758
0 commit comments