Skip to content

Commit

Permalink
Deprecate DatagridManagerInterface
Browse files Browse the repository at this point in the history
The modelManager provided by persistence bundle will be final in next release.
Asking someone to rewrite all the method of the model manager, just to change
the default sort values or default per page options does not make sens then.
We should promote the AbstractAdmin method override, or one day implement a
service specific to this configuration.
  • Loading branch information
VincentLanglet committed Oct 31, 2020
1 parent be653e2 commit 335b595
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
6 changes: 6 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
UPGRADE 3.x
===========

### Deprecated `Sonata\AdminBundle\Model\DatagridManagerInterface` interface.

This interface has been deprecated without replacement.

`ModelManagerInterface::getDefaultSortValues()` won't be used anymore.

UPGRADE FROM 3.77 to 3.78
=========================

Expand Down
8 changes: 5 additions & 3 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public function preBatchAction($actionName, ProxyQueryInterface $query, array &$
public function getFilterParameters()
{
$parameters = array_merge(
$this->getModelManager()->getDefaultSortValues($this->getClass()),
$this->getModelManager()->getDefaultSortValues($this->getClass()), // NEXT_MAJOR: Remove this line.
$this->datagridValues, // NEXT_MAJOR: Remove this line.
$this->getDefaultSortValues(),
$this->getDefaultFilterValues()
Expand Down Expand Up @@ -1713,7 +1713,7 @@ public function getMaxPerPage()
{
// NEXT_MAJOR: Remove this line and uncomment the following.
return $this->maxPerPage;
// $sortValues = $this->getModelManager()->getDefaultSortValues($this->class);
// $sortValues = $this->getDefaultSortValues();

// return $sortValues['_per_page'] ?? 25;
}
Expand Down Expand Up @@ -2932,7 +2932,7 @@ public function getPerPageOptions()
{
// NEXT_MAJOR: Remove this line and uncomment the following
return $this->perPageOptions;
// $perPageOptions = $this->getModelManager()->getDefaultPerPageOptions($this->class);
// $perPageOptions = [10, 25, 50, 100, 250];
// $perPageOptions[] = $this->getMaxPerPage();
//
// $perPageOptions = array_unique($perPageOptions);
Expand Down Expand Up @@ -3326,7 +3326,9 @@ protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterfa
*/
final protected function getDefaultSortValues(): array
{
// NEXT_MAJOR: Use the next line instead.
$defaultSortValues = [];
// $defaultSortValues = ['_page' => 1, '_per_page' => 25];

$this->configureDefaultSortValues($defaultSortValues);

Expand Down
12 changes: 4 additions & 8 deletions src/Model/DatagridManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
/**
* A datagrid manager is a bridge between the model classes and the admin datagrid functionality.
*
* NEXT_MAJOR: Remove this interface
*
* @deprecated since sonata-project/admin-bundle 3.x
*
* @method array getDefaultPerPageOptions(string $class)
*/
interface DatagridManagerInterface
Expand All @@ -28,12 +32,4 @@ interface DatagridManagerInterface
* @return array<string, int|string>
*/
public function getDefaultSortValues($class);

// NEXT_MAJOR: Uncomment the following lines.
// /**
// * Return all the allowed _per_page values.
// *
// * @return array<int>
// */
// public function getDefaultPerPageOptions(string $class): array;
}
2 changes: 2 additions & 0 deletions src/Model/ModelManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Sonata\Exporter\Source\SourceIteratorInterface;

/**
* NEXT_MAJOR: Stop to extend DatagridManagerInterface.
*
* A model manager is a bridge between the model classes and the admin functionality.
*
* @method bool supportsQuery(object $query)
Expand Down
6 changes: 6 additions & 0 deletions tests/App/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D
return [];
}

/**
* NEXT_MAJOR: Remove this method.
*/
public function getDefaultSortValues($class)
{
return [];
}

/**
* NEXT_MAJOR: Remove this method.
*/
public function getDefaultPerPageOptions(string $class): array
{
return [];
Expand Down

0 comments on commit 335b595

Please sign in to comment.