From 8ec6eb4307187e33bdb554b2447597e0801e52c0 Mon Sep 17 00:00:00 2001 From: Giulio Marcon Date: Fri, 23 Jan 2026 18:12:45 +0100 Subject: [PATCH] Fix Datatables error "Undefined array key 2" when using the "Manage media" utility, triggered when setting the ordering for media object in "Local files" or "External files", and then switching to "Unused files" --- app/Http/RequestHandlers/ManageMediaData.php | 6 +++++- app/Services/DatatablesService.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Http/RequestHandlers/ManageMediaData.php b/app/Http/RequestHandlers/ManageMediaData.php index fec0fabc882..fb998d87603 100644 --- a/app/Http/RequestHandlers/ManageMediaData.php +++ b/app/Http/RequestHandlers/ManageMediaData.php @@ -215,7 +215,11 @@ public function handle(ServerRequestInterface $request): ResponseInterface ->map(static fn (string $file): array => (array) $file); $search_columns = [0]; - $sort_columns = [0 => 0]; + $sort_columns = [ + 0 => 0, + 1 => 0, + 2 => 0, + ]; $callback = function (array $row) use ($data_filesystem, $media_trees): array { try { diff --git a/app/Services/DatatablesService.php b/app/Services/DatatablesService.php index 2c53e2fed00..e2ebd99467e 100644 --- a/app/Services/DatatablesService.php +++ b/app/Services/DatatablesService.php @@ -76,6 +76,10 @@ public function handleCollection(ServerRequestInterface $request, Collection $co if ($order !== []) { $collection = $collection->sort(static function (array $row1, array $row2) use ($order, $sort_columns): int { foreach ($order as $column) { + if (!isset($sort_columns[$column['column']])) { + continue; + } + $key = $sort_columns[$column['column']]; $dir = $column['dir'];