-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These deprecations were introduced in 3.66. This replaces calls to `ModelManagerInterface::getPaginationParameters` for `DatagridInterface::getPaginationParameters` and `ModelManagerInterface::getSortParameters` for `DatagridInterface::getSortParameters`.
- Loading branch information
Showing
7 changed files
with
241 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Twig\Extension; | ||
|
||
use Sonata\AdminBundle\Admin\AdminInterface; | ||
use Sonata\AdminBundle\Admin\FieldDescriptionInterface; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this class. | ||
* | ||
* @internal | ||
*/ | ||
final class PaginationExtension extends AbstractExtension | ||
{ | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('sonata_pagination_parameters', [$this, 'getPaginationParameters']), | ||
new TwigFunction('sonata_sort_parameters', [$this, 'getSortParameters']), | ||
]; | ||
} | ||
|
||
public function getPaginationParameters(AdminInterface $admin, int $page): array | ||
{ | ||
if (method_exists($admin->getDatagrid(), 'getPaginationParameters')) { | ||
return $admin->getDatagrid()->getPaginationParameters($page); | ||
} | ||
|
||
return $admin->getModelManager()->getPaginationParameters($admin->getDatagrid(), $page); | ||
} | ||
|
||
public function getSortParameters(FieldDescriptionInterface $fieldDescription, AdminInterface $admin): array | ||
{ | ||
if (method_exists($admin->getDatagrid(), 'getSortParameters')) { | ||
return $admin->getDatagrid()->getSortParameters($fieldDescription); | ||
} | ||
|
||
return $admin->getModelManager()->getSortParameters($fieldDescription, $admin->getDatagrid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Twig\Extension; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sonata\AdminBundle\Admin\AdminInterface; | ||
use Sonata\AdminBundle\Admin\FieldDescriptionInterface; | ||
use Sonata\AdminBundle\Datagrid\DatagridInterface; | ||
use Sonata\AdminBundle\Model\ModelManagerInterface; | ||
use Sonata\AdminBundle\Twig\Extension\PaginationExtension; | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this class. | ||
*/ | ||
final class PaginationExtensionTest extends TestCase | ||
{ | ||
public function testGetPaginationParameters(): void | ||
{ | ||
$paginationParameters = [ | ||
'filter' => [ | ||
'_page' => 1, | ||
], | ||
]; | ||
|
||
$datagrid = $this->getMockBuilder(DatagridInterface::class) | ||
->addMethods(['getPaginationParameters']) | ||
->getMockForAbstractClass(); | ||
$datagrid | ||
->method('getPaginationParameters') | ||
->willReturn($paginationParameters); | ||
$admin = $this->createStub(AdminInterface::class); | ||
$admin | ||
->method('getDatagrid') | ||
->willReturn($datagrid); | ||
|
||
$extension = new PaginationExtension(); | ||
$this->assertSame($paginationParameters, $extension->getPaginationParameters($admin, 1)); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testGetPaginationParametersFromModelManager(): void | ||
{ | ||
$paginationParameters = [ | ||
'filter' => [ | ||
'_page' => 1, | ||
], | ||
]; | ||
|
||
$datagrid = $this->createStub(DatagridInterface::class); | ||
$modelManager = $this->createStub(ModelManagerInterface::class); | ||
$modelManager | ||
->method('getPaginationParameters') | ||
->willReturn($paginationParameters); | ||
|
||
$admin = $this->createStub(AdminInterface::class); | ||
$admin | ||
->method('getDatagrid') | ||
->willReturn($datagrid); | ||
|
||
$admin | ||
->method('getModelManager') | ||
->willReturn($modelManager); | ||
|
||
$extension = new PaginationExtension(); | ||
$this->assertSame($paginationParameters, $extension->getPaginationParameters($admin, 1)); | ||
} | ||
|
||
public function testGetSortParameters(): void | ||
{ | ||
$sortParameters = [ | ||
'filter' => [ | ||
'_sort_order' => 'ASC', | ||
'_sort_by' => 'name', | ||
], | ||
]; | ||
|
||
$datagrid = $this->getMockBuilder(DatagridInterface::class) | ||
->addMethods(['getSortParameters']) | ||
->getMockForAbstractClass(); | ||
$datagrid | ||
->method('getSortParameters') | ||
->willReturn($sortParameters); | ||
$admin = $this->createStub(AdminInterface::class); | ||
$admin | ||
->method('getDatagrid') | ||
->willReturn($datagrid); | ||
|
||
$fieldDescription = $this->createStub(FieldDescriptionInterface::class); | ||
|
||
$extension = new PaginationExtension(); | ||
$this->assertSame($sortParameters, $extension->getSortParameters($fieldDescription, $admin)); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testGetSortParametersFromModelManager(): void | ||
{ | ||
$sortParameters = [ | ||
'filter' => [ | ||
'_sort_order' => 'ASC', | ||
'_sort_by' => 'name', | ||
], | ||
]; | ||
|
||
$datagrid = $this->createStub(DatagridInterface::class); | ||
$modelManager = $this->createStub(ModelManagerInterface::class); | ||
$modelManager | ||
->method('getSortParameters') | ||
->willReturn($sortParameters); | ||
|
||
$admin = $this->createStub(AdminInterface::class); | ||
$admin | ||
->method('getDatagrid') | ||
->willReturn($datagrid); | ||
|
||
$admin | ||
->method('getModelManager') | ||
->willReturn($modelManager); | ||
|
||
$fieldDescription = $this->createStub(FieldDescriptionInterface::class); | ||
|
||
$extension = new PaginationExtension(); | ||
$this->assertSame($sortParameters, $extension->getSortParameters($fieldDescription, $admin)); | ||
} | ||
} |