Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate DatagridManagerInterface #6458

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
*
* @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