Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge 2.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Mar 22, 2020
2 parents 36ff420 + 7efafcf commit 9ec8b61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Model/ModelManager.php
Expand Up @@ -374,7 +374,7 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D
{
$values = $datagrid->getValues();

if ($fieldDescription->getName() === $values['_sort_by']->getName()) {
if ($this->isFieldAlreadySorted($fieldDescription, $datagrid)) {
if ('ASC' === $values['_sort_order']) {
$values['_sort_order'] = 'DESC';
} else {
Expand All @@ -397,7 +397,9 @@ public function getPaginationParameters(DatagridInterface $datagrid, $page)
{
$values = $datagrid->getValues();

$values['_sort_by'] = $values['_sort_by']->getName();
if (isset($values['_sort_by']) && $values['_sort_by'] instanceof FieldDescriptionInterface) {
$values['_sort_by'] = $values['_sort_by']->getName();
}
$values['_page'] = $page;

return ['filter' => $values];
Expand Down Expand Up @@ -550,4 +552,16 @@ protected function camelize($property)
{
return preg_replace(['/(^|_)+(.)/e', '/\.(.)/e'], ["strtoupper('\\2')", "'_'.strtoupper('\\1')"], $property);
}

private function isFieldAlreadySorted(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid): bool
{
$values = $datagrid->getValues();

if (!isset($values['_sort_by']) || !$values['_sort_by'] instanceof FieldDescriptionInterface) {
return false;
}

return $values['_sort_by']->getName() === $fieldDescription->getName()
|| $values['_sort_by']->getName() === $fieldDescription->getOption('sortable');
}
}
Expand Up @@ -31,6 +31,10 @@ public function testDocumentTreeDefaultValues(): void
'kernel.bundles',
[]
);
$this->container->setParameter(
'sonata.admin.configuration.use_intl_templates',
false
);
$this->load(['document_tree' => []]);

$this->assertContainerBuilderHasParameter(
Expand Down

0 comments on commit 9ec8b61

Please sign in to comment.