From 4dcde56891875cd311b1942863dd0b1c31899d14 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 5 Oct 2020 21:06:52 +0200 Subject: [PATCH] Deprecate DatagridManagerInterface 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. --- UPGRADE-3.x.md | 6 ++++++ src/Admin/AbstractAdmin.php | 8 +++++--- src/Model/DatagridManagerInterface.php | 12 ++++-------- src/Model/ModelManagerInterface.php | 2 ++ tests/App/Model/ModelManager.php | 6 ++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 4065ea8ae9..d7ed8bea97 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -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 ========================= diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 6a4a8ac931..be83a902ba 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -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() @@ -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; } @@ -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); @@ -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); diff --git a/src/Model/DatagridManagerInterface.php b/src/Model/DatagridManagerInterface.php index fae7a9ff88..bfe57055d6 100644 --- a/src/Model/DatagridManagerInterface.php +++ b/src/Model/DatagridManagerInterface.php @@ -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 @@ -28,12 +32,4 @@ interface DatagridManagerInterface * @return array */ public function getDefaultSortValues($class); - -// NEXT_MAJOR: Uncomment the following lines. -// /** -// * Return all the allowed _per_page values. -// * -// * @return array -// */ -// public function getDefaultPerPageOptions(string $class): array; } diff --git a/src/Model/ModelManagerInterface.php b/src/Model/ModelManagerInterface.php index 37199ae402..112468425e 100644 --- a/src/Model/ModelManagerInterface.php +++ b/src/Model/ModelManagerInterface.php @@ -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) diff --git a/tests/App/Model/ModelManager.php b/tests/App/Model/ModelManager.php index 0f2eb3fc9f..b0e739a587 100644 --- a/tests/App/Model/ModelManager.php +++ b/tests/App/Model/ModelManager.php @@ -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 [];