|
9 | 9 | use Kirby\Exception\DuplicateException; |
10 | 10 | use Kirby\Exception\LogicException; |
11 | 11 | use Kirby\Exception\PermissionException; |
| 12 | +use Kirby\Form\Field\PageListField; |
| 13 | +use Kirby\Form\Fields; |
12 | 14 | use Kirby\Toolkit\A; |
13 | 15 | use Kirby\Toolkit\Str; |
14 | 16 |
|
@@ -210,33 +212,36 @@ public function validateMoveToTemplate(Site|Page $parent): void |
210 | 212 | { |
211 | 213 | $allowed = []; |
212 | 214 |
|
213 | | - // collect all allowed subpage templates |
214 | | - // from all pages sections in the blueprint |
215 | | - // (only consider page sections that list pages |
216 | | - // of the targeted new parent page) |
217 | | - $sections = array_filter( |
218 | | - $parent->blueprint()->sections(), |
219 | | - fn ($section) => |
220 | | - $section->type() === 'pages' && |
221 | | - $section->parent()->is($parent) |
222 | | - ); |
| 215 | + // collect all allowed subpage templates from all page list |
| 216 | + // fields in the blueprint (only consider fields that list |
| 217 | + // pages of the targeted new parent page) |
| 218 | + $hasPageList = false; |
| 219 | + |
| 220 | + foreach (Fields::for($parent) as $field) { |
| 221 | + if ( |
| 222 | + $field instanceof PageListField === false || |
| 223 | + $field->parentModel()->is($parent) === false |
| 224 | + ) { |
| 225 | + continue; |
| 226 | + } |
| 227 | + |
| 228 | + $hasPageList = true; |
223 | 229 |
|
224 | | - // check if the parent has at least one pages section |
225 | | - if ($sections === []) { |
| 230 | + // go through all allowed templates and |
| 231 | + // add the name to the allowlist |
| 232 | + foreach ($field->templates() as $template) { |
| 233 | + $allowed[] = $template; |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + // check if the parent has at least one page list field |
| 238 | + if ($hasPageList === false) { |
226 | 239 | throw new LogicException( |
227 | 240 | key: 'page.move.noSections', |
228 | 241 | data: ['parent' => $parent->id() ?? '/'] |
229 | 242 | ); |
230 | 243 | } |
231 | 244 |
|
232 | | - // go through all allowed templates and |
233 | | - // add the name to the allowlist |
234 | | - foreach ($sections as $section) { |
235 | | - foreach ($section->templates() as $template) { |
236 | | - $allowed[] = $template; |
237 | | - } |
238 | | - } |
239 | | - |
240 | 245 | // check if the template of this page is allowed as subpage type |
241 | 246 | // for the potential new parent |
242 | 247 | if ( |
|
0 commit comments