Skip to content

Commit

Permalink
Merge pull request #96 from chialab/fix/correctly-merge-pagination-op…
Browse files Browse the repository at this point in the history
…tions

Correctly merge pagination options for children
  • Loading branch information
edoardocavazza authored Jun 11, 2024
2 parents cf51034 + 6127888 commit 310421b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Traits/GenericActionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ protected function loadFilteredChildren(Folder $folder): array
$order = ['Trees.tree_left' => 'ASC'];
}

$sortAllowlist = $this->paginate['sortableFields'] ?? (array)$this->request->getQuery('sort');
$this->paginate['sortableFields'] = array_merge($sortAllowlist, array_keys($order));

$children = $this->Objects->loadRelatedObjects($folder['uname'], 'folders', 'children', $this->Filters->fromQuery());

return $this->paginate($children->order([], true), ['order' => $order])->toList();
$settings = Hash::merge($this->paginate, [
'order' => $order,
'sortableFields' => array_merge($this->paginate['sortableFields'] ?? (array)$this->request->getQuery('sort'), array_keys($order)),
]);
if (isset($settings['Children'])) {
$settings = Hash::merge($settings, [
'Children' => [
'order' => $order,
'sortableFields' => array_merge($this->paginate['Children']['sortableFields'] ?? (array)$this->request->getQuery('sort'), array_keys($order)),
],
]);
}

return $this->paginate($children->order([], true), $settings)->toList();
}

/**
Expand Down

0 comments on commit 310421b

Please sign in to comment.