From 12a58d1fa332eb3616f1709e8131193993f46773 Mon Sep 17 00:00:00 2001 From: "denis.flaven@combodo.com" Date: Mon, 14 Nov 2022 18:37:20 +0100 Subject: [PATCH 1/4] =?UTF-8?q?N=C2=B05619=20-=20hide=20newsroom=20menu=20?= =?UTF-8?q?when=20no=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php | 10 ++++++++++ .../Layout/NavigationMenu/NavigationMenuFactory.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php index 1b11b869d7..efc1473610 100644 --- a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php +++ b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php @@ -49,6 +49,16 @@ public static function MakeNewsroomMenuForNavigationMenu() return $oMenu; } + /** + * Check if there is any Newsroom provider configured + * @return boolean + */ + public static function HasProviders() + { + $aProviders = MetaModel::EnumPlugins('iNewsroomProvider'); + return count($aProviders) > 0; + } + /** * Prepare parameters for the newsroom JS widget * diff --git a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php index 744541d6d0..513ca903b7 100644 --- a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php +++ b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php @@ -48,7 +48,7 @@ public static function MakeStandard() { $oNewsroomMenu = null; - if (MetaModel::GetConfig()->Get('newsroom_enabled')) + if (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders()) { $oNewsroomMenu = NewsroomMenuFactory::MakeNewsroomMenuForNavigationMenu(); } From 1982771c2884f0c85ddf3c61d0091d1fea9229ce Mon Sep 17 00:00:00 2001 From: "denis.flaven@combodo.com" Date: Thu, 17 Nov 2022 11:09:12 +0100 Subject: [PATCH 2/4] =?UTF-8?q?N=C2=B05619=20-=20fixed=20crash=20when=20no?= =?UTF-8?q?=20provider=20at=20all!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Base/Layout/NavigationMenu/NavigationMenu.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php index 6229d755cb..7793016bbd 100644 --- a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php +++ b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php @@ -35,6 +35,7 @@ use UIExtKeyWidget; use UserRights; use utils; +use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenuFactory; /** * Class NavigationMenu @@ -269,7 +270,7 @@ public function GetSubBlocks(): array */ public function IsNewsroomEnabled(): bool { - return MetaModel::GetConfig()->Get('newsroom_enabled'); + return (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders()); } /** From c5640db511c569805bb42b7c2cfbcf6f15d89cd9 Mon Sep 17 00:00:00 2001 From: "denis.flaven@combodo.com" Date: Thu, 6 Apr 2023 14:49:45 +0200 Subject: [PATCH 3/4] Cleanup: moved HasProvider() out of the Factory --- .../PopoverMenu/NewsroomMenu/NewsroomMenu.php | 12 ++++++++++++ .../PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php | 10 ---------- .../UI/Base/Layout/NavigationMenu/NavigationMenu.php | 3 +-- .../Layout/NavigationMenu/NavigationMenuFactory.php | 3 ++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php index f4f6a637d4..af86e44650 100644 --- a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php +++ b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php @@ -21,6 +21,7 @@ use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu; +use MetaModel; /** * Class NewsroomMenu @@ -65,4 +66,15 @@ public function GetParamsAsJson(): string { return json_encode($this->aParams); } + + /** + * Check if there is any Newsroom provider configured + * @since 3.1.0 N°5619 + * @return boolean + */ + public static function HasProviders(): bool + { + $aProviders = MetaModel::EnumPlugins('iNewsroomProvider'); + return count($aProviders) > 0; + } } \ No newline at end of file diff --git a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php index efc1473610..1b11b869d7 100644 --- a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php +++ b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php @@ -49,16 +49,6 @@ public static function MakeNewsroomMenuForNavigationMenu() return $oMenu; } - /** - * Check if there is any Newsroom provider configured - * @return boolean - */ - public static function HasProviders() - { - $aProviders = MetaModel::EnumPlugins('iNewsroomProvider'); - return count($aProviders) > 0; - } - /** * Prepare parameters for the newsroom JS widget * diff --git a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php index 7793016bbd..c2b572ab41 100644 --- a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php +++ b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php @@ -35,7 +35,6 @@ use UIExtKeyWidget; use UserRights; use utils; -use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenuFactory; /** * Class NavigationMenu @@ -270,7 +269,7 @@ public function GetSubBlocks(): array */ public function IsNewsroomEnabled(): bool { - return (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders()); + return (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenu::HasProviders()); } /** diff --git a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php index 513ca903b7..f66ba171cc 100644 --- a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php +++ b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenuFactory.php @@ -21,6 +21,7 @@ use ApplicationContext; +use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenu; use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenuFactory; use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuFactory; use MetaModel; @@ -48,7 +49,7 @@ public static function MakeStandard() { $oNewsroomMenu = null; - if (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders()) + if (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenu::HasProviders()) { $oNewsroomMenu = NewsroomMenuFactory::MakeNewsroomMenuForNavigationMenu(); } From a92c91d462660f031c5c97e2905555d871b5547c Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 6 Apr 2023 17:55:08 +0200 Subject: [PATCH 4/4] PHPDoc --- .../UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php index af86e44650..d4edfaa359 100644 --- a/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php +++ b/sources/application/UI/Base/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php @@ -70,7 +70,7 @@ public function GetParamsAsJson(): string /** * Check if there is any Newsroom provider configured * @since 3.1.0 N°5619 - * @return boolean + * @return bool */ public static function HasProviders(): bool {