$path]); } /** * Bereits vorhandene Bilder im öffentlichen Bereich (veröffentlicht oder zur Veröffentlichung vorgemerkt). * * @return array */ public static function imageOptions(): array { $options = []; foreach (['media_public', 'cms_incoming'] as $disk) { try { $files = Storage::disk($disk)->allFiles(rtrim(self::PREFIX, '/')); } catch (Throwable) { $files = []; } foreach ($files as $file) { $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (self::isPublicPath($file) && in_array($extension, self::IMAGE_EXTENSIONS, true)) { $options[$file] = substr($file, strlen(self::PREFIX)); } } } ksort($options); return $options; } /** * Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste). */ public static function fromUploadState(mixed $state): ?string { if (is_array($state)) { $state = array_values($state)[0] ?? null; } return is_string($state) && $state !== '' ? $state : null; } /** * Bildadresse für Darstellung und Blockvorschau. In der Vorschau kann ein noch nicht gespeicherter Upload vorliegen. * * @param array $refs */ public static function imageUrl(array $refs, string $key = 'image'): ?string { $upload = $refs['_upload'] ?? null; $upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload; if ($upload instanceof TemporaryUploadedFile) { try { return $upload->temporaryUrl(); } catch (Throwable) { return null; } } if (self::isPublicPath($upload)) { return self::url($upload); } $path = $refs[$key] ?? null; return self::isPublicPath($path) ? self::url($path) : null; } }