Skip to content

Commit

Permalink
Deprecate DatagridManagerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Oct 26, 2020
1 parent 7002ecd commit 8885b94
Show file tree
Hide file tree
Showing 5 changed files with 21 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.

`ModelManager::getDefaultSortValues()` won't be use 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
10 changes: 2 additions & 8 deletions src/Model/DatagridManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* A datagrid manager is a bridge between the model classes and the admin datagrid functionality.
*
* NEXT_MAJOR: Remove this interface
*
* @method array getDefaultPerPageOptions(string $class)
*/
interface DatagridManagerInterface
Expand All @@ -28,12 +30,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 8885b94

Please sign in to comment.