From cdd85c356480b622e2cd292820a704a49094cdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20B=C5=82oszyk?= Date: Mon, 11 Jan 2021 21:15:36 +0100 Subject: [PATCH 1/2] Fix template setters in AbstractAdmin Update tests/Templating/MutableTemplateRegistryTest.php Co-authored-by: Javier Spagnoletti Update src/Templating/MutableTemplateRegistry.php Co-authored-by: Javier Spagnoletti --- src/Admin/AbstractAdmin.php | 11 ----------- src/Templating/MutableTemplateRegistry.php | 2 ++ .../MutableTemplateRegistryAwareInterface.php | 19 +++++++++++++++++++ .../MutableTemplateRegistryTest.php | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index faa9d6ce27..2aefec71fe 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -1195,11 +1195,6 @@ final public function setTemplateRegistry(MutableTemplateRegistryInterface $temp $this->templateRegistry = $templateRegistry; } - /** - * @deprecated since sonata-project/admin-bundle 3.76, will be dropped in 4.0. Use TemplateRegistry services instead - * - * @param array $templates - */ public function setTemplates(array $templates) { // NEXT_MAJOR: Remove this line @@ -1208,12 +1203,6 @@ public function setTemplates(array $templates) $this->getTemplateRegistry()->setTemplates($templates); } - /** - * @deprecated since sonata-project/admin-bundle 3.76, will be dropped in 4.0. Use TemplateRegistry services instead - * - * @param string $name - * @param string $template - */ public function setTemplate($name, $template) { // NEXT_MAJOR: Remove this line diff --git a/src/Templating/MutableTemplateRegistry.php b/src/Templating/MutableTemplateRegistry.php index a3e8f9d462..8741cccf57 100644 --- a/src/Templating/MutableTemplateRegistry.php +++ b/src/Templating/MutableTemplateRegistry.php @@ -22,7 +22,9 @@ final class MutableTemplateRegistry extends AbstractTemplateRegistry implements // public function setTemplates(array $templates): void public function setTemplates(array $templates) { + //NEXT_MAJOR: use array merge and update the doc https://github.com/sonata-project/SonataAdminBundle/blob/3.x/docs/reference/templates.rst $this->templates = $templates; + //$this->templates = $templates + $this->templates; } // NEXT_MAJOR: change method declaration for new one diff --git a/src/Templating/MutableTemplateRegistryAwareInterface.php b/src/Templating/MutableTemplateRegistryAwareInterface.php index 76e900cd73..05ea7d0021 100644 --- a/src/Templating/MutableTemplateRegistryAwareInterface.php +++ b/src/Templating/MutableTemplateRegistryAwareInterface.php @@ -30,4 +30,23 @@ interface MutableTemplateRegistryAwareInterface // NEXT_MAJOR: uncomment this method in 4.0 //public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void; + + /** + * NEXT_MAJOR: remove this method declaration with docblock and uncomment code below. + * + * @param string $name + * @param string $template + */ + public function setTemplate($name, $template); + + //public function setTemplate(string $name, string $template); + + /** + * NEXT_MAJOR: remove this method declaration and uncomment code below. + * + * @param array $templates + */ + public function setTemplates(array $templates); + + //public function setTemplates(array $templates): void; } diff --git a/tests/Templating/MutableTemplateRegistryTest.php b/tests/Templating/MutableTemplateRegistryTest.php index a7b0558416..6c6f895575 100644 --- a/tests/Templating/MutableTemplateRegistryTest.php +++ b/tests/Templating/MutableTemplateRegistryTest.php @@ -44,7 +44,9 @@ public function testGetTemplates(): void ]; $this->templateRegistry->setTemplates($templates); + // NEXT_MAJOR: remove this first assert and uncomment second $this->assertSame($templates, $this->templateRegistry->getTemplates()); + //$this->assertSame($templates + ['list' => '@FooAdmin/CRUD/list.html.twig'], $this->templateRegistry->getTemplates()); } /** From 3a6b0b81b51f99b104ef0fcbdfb4e7b979102114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20B=C5=82oszyk?= Date: Sun, 17 Jan 2021 12:29:32 +0100 Subject: [PATCH 2/2] Update src/Templating/MutableTemplateRegistry.php Co-authored-by: Javier Spagnoletti --- src/Templating/MutableTemplateRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Templating/MutableTemplateRegistry.php b/src/Templating/MutableTemplateRegistry.php index 8741cccf57..8abf6144db 100644 --- a/src/Templating/MutableTemplateRegistry.php +++ b/src/Templating/MutableTemplateRegistry.php @@ -22,7 +22,7 @@ final class MutableTemplateRegistry extends AbstractTemplateRegistry implements // public function setTemplates(array $templates): void public function setTemplates(array $templates) { - //NEXT_MAJOR: use array merge and update the doc https://github.com/sonata-project/SonataAdminBundle/blob/3.x/docs/reference/templates.rst + //NEXT_MAJOR: merge arrays and update the doc https://github.com/sonata-project/SonataAdminBundle/blob/3.x/docs/reference/templates.rst $this->templates = $templates; //$this->templates = $templates + $this->templates; }