From 7954aabfbf2545727ed8368be30c6f31e4fa3f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Sat, 1 May 2021 15:43:31 +0200 Subject: [PATCH 1/4] Allow admin extension to configure admin at initialize time --- src/Admin/AbstractAdmin.php | 6 ++++++ src/Admin/AbstractAdminExtension.php | 7 +++++++ src/Admin/AdminExtensionInterface.php | 1 + 3 files changed, 14 insertions(+) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 2840161c79..5acba13d67 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -588,6 +588,12 @@ public function initialize() */ public function configure() { + foreach ($this->getExtensions() as $extension) { + // NEXT_MAJOR: remove method_exists check + if (method_exists($extension, 'configure')) { + $extension->configure($this); + } + } } public function update($object) diff --git a/src/Admin/AbstractAdminExtension.php b/src/Admin/AbstractAdminExtension.php index bdf04ec7d3..179fa3d3a8 100644 --- a/src/Admin/AbstractAdminExtension.php +++ b/src/Admin/AbstractAdminExtension.php @@ -110,6 +110,13 @@ public function getAccessMapping(AdminInterface $admin) return []; } + /** + * @phpstan-param AdminInterface $admin + */ + public function configure(AdminInterface $admin): void + { + } + /** * @phpstan-param AdminInterface $admin */ diff --git a/src/Admin/AdminExtensionInterface.php b/src/Admin/AdminExtensionInterface.php index e24f134cd2..ce67224b68 100644 --- a/src/Admin/AdminExtensionInterface.php +++ b/src/Admin/AdminExtensionInterface.php @@ -26,6 +26,7 @@ * @author Thomas Rabaix * * @method array getAccessMapping(AdminInterface $admin) + * @method array configure(AdminInterface $admin) * @method array configureBatchActions(AdminInterface $admin, array $actions) * @method array configureExportFields(AdminInterface $admin, array $fields) * @method array configureActionButtons(AdminInterface $admin, array $list, string $action, object $object) From 64d534b9e332a98fedf1340b3ea999d9b8f5b110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Sat, 1 May 2021 15:57:27 +0200 Subject: [PATCH 2/4] Call AdminExtensionInterface::configure in AbstractAdmin::initialize instead of AbstractAdmin::configure --- src/Admin/AbstractAdmin.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 5acba13d67..3a64254972 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -581,13 +581,7 @@ public function initialize() $this->baseCodeRoute = $this->getCode(); $this->configure(); - } - /** - * NEXT_MAJOR: Restrict visibility to protected. - */ - public function configure() - { foreach ($this->getExtensions() as $extension) { // NEXT_MAJOR: remove method_exists check if (method_exists($extension, 'configure')) { @@ -596,6 +590,13 @@ public function configure() } } + /** + * NEXT_MAJOR: Restrict visibility to protected. + */ + public function configure() + { + } + public function update($object) { $this->preUpdate($object); From 59b35f3dbcfca0c1a28294a6e684bbd9a6a5b82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Sat, 1 May 2021 15:57:52 +0200 Subject: [PATCH 3/4] Add AdminExtensionInterface::configure NEXT_MAJOR method template --- src/Admin/AdminExtensionInterface.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Admin/AdminExtensionInterface.php b/src/Admin/AdminExtensionInterface.php index ce67224b68..dde81fad81 100644 --- a/src/Admin/AdminExtensionInterface.php +++ b/src/Admin/AdminExtensionInterface.php @@ -166,6 +166,13 @@ public function alterObject(AdminInterface $admin, $object); */ public function getPersistentParameters(AdminInterface $admin); + /** + * Get a chance to configure admin before used. + * + * @phpstan-param AdminInterface $admin + */ +// public function configure(AdminInterface $admin): void; + /** * Get a chance to add persistent parameters. * From f6adc268326d391a885d77ad7e75922a2541be09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Sun, 2 May 2021 09:41:44 +0200 Subject: [PATCH 4/4] Fixed AdminExtensionInterface::configure phpdoc return type --- src/Admin/AdminExtensionInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin/AdminExtensionInterface.php b/src/Admin/AdminExtensionInterface.php index dde81fad81..121614aac0 100644 --- a/src/Admin/AdminExtensionInterface.php +++ b/src/Admin/AdminExtensionInterface.php @@ -26,7 +26,7 @@ * @author Thomas Rabaix * * @method array getAccessMapping(AdminInterface $admin) - * @method array configure(AdminInterface $admin) + * @method void configure(AdminInterface $admin) * @method array configureBatchActions(AdminInterface $admin, array $actions) * @method array configureExportFields(AdminInterface $admin, array $fields) * @method array configureActionButtons(AdminInterface $admin, array $list, string $action, object $object)