|
17 | 17 | use Bnomei\TurboStopwatch; |
18 | 18 | use Bnomei\TurboUuidCache; |
19 | 19 | use Kirby\Cms\App; |
| 20 | +use Kirby\Cms\File; |
20 | 21 | use Kirby\Cms\Files; |
21 | 22 | use Kirby\Cms\Page; |
22 | 23 | use Kirby\Cms\Pages; |
23 | 24 | use Kirby\Content\Field; |
24 | 25 | use Kirby\Filesystem\F; |
25 | 26 | use Kirby\Http\Route; |
| 27 | +use Kirby\Toolkit\A; |
26 | 28 |
|
27 | 29 | @include_once __DIR__.'/vendor/autoload.php'; |
28 | 30 |
|
@@ -286,26 +288,45 @@ function tubs(array|string $key, Closure $closure): mixed |
286 | 288 | }, |
287 | 289 | ], |
288 | 290 | 'fieldMethods' => [ |
| 291 | + 'toFileTurbo' => function (Field $field): ?File { |
| 292 | + return $field->toFilesTurbo()->first(); |
| 293 | + }, |
289 | 294 | 'toFilesTurbo' => function (Field $field): Files { |
290 | 295 | if (kirby()->option('cache.uuid.type') === 'turbo-uuid') { |
291 | | - $ids = []; |
292 | | - foreach ($field->yaml() as $uuid) { // @phpstan-ignore-line |
293 | | - $uuid = 'file/'.substr($uuid, 7, 2).'/'.substr($uuid, 9); |
294 | | - $ids[] = kirby()->cache('uuid')->get($uuid); |
| 296 | + $files = []; |
| 297 | + $pages = []; |
| 298 | + $cache = kirby()->cache('uuid'); |
| 299 | + foreach ($field->yaml() as $fileKey) { // @phpstan-ignore-line |
| 300 | + $fileKey = 'file/'.substr($fileKey, 7, 2).'/'.substr($fileKey, 9); |
| 301 | + if ($data =$cache->get($fileKey)) { |
| 302 | + $parentUuid = is_array($data) ? A::get($data, 'parent') : null; |
| 303 | + if (! $parentUuid) { |
| 304 | + continue; |
| 305 | + } |
| 306 | + $parentKey = 'page/'.substr($parentUuid, 7, 2).'/'.substr($parentUuid, 9); |
| 307 | + if ($parentId =$cache->get($parentKey)) { |
| 308 | + $pages[$parentId] = A::get($pages, $parentId, kirby()->page($parentId)); |
| 309 | + $files[] = $pages[$parentId]?->file(A::get($data, 'filename')); |
| 310 | + } |
| 311 | + } |
295 | 312 | } |
296 | 313 |
|
297 | | - return new Files(array_filter($ids)); |
| 314 | + return new Files(array_filter($files)); |
298 | 315 | } |
299 | 316 |
|
300 | 317 | // default |
301 | 318 | return $field->toFiles(); // @phpstan-ignore-line |
302 | 319 | }, |
| 320 | + 'toPageTurbo' => function (Field $field): ?Page { |
| 321 | + return $field->toPagesTurbo()->first(); |
| 322 | + }, |
303 | 323 | 'toPagesTurbo' => function (Field $field): Pages { |
304 | 324 | if (kirby()->option('cache.uuid.type') === 'turbo-uuid') { |
305 | 325 | $ids = []; |
| 326 | + $cache = kirby()->cache('uuid'); |
306 | 327 | foreach ($field->yaml() as $uuid) { // @phpstan-ignore-line |
307 | | - $uuid = 'page/'.substr($uuid, 7, 2).'/'.substr($uuid, 9); |
308 | | - $ids[] = kirby()->cache('uuid')->get($uuid); |
| 328 | + $key = 'page/'.substr($uuid, 7, 2).'/'.substr($uuid, 9); |
| 329 | + $ids[] = $cache->get($key); |
309 | 330 | } |
310 | 331 |
|
311 | 332 | return new Pages(array_filter($ids)); |
|
0 commit comments