mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Fix merge: 5619/5620/6293 dev lost because due to folder sources/Application renaming
This commit is contained in:
@@ -49,6 +49,16 @@ class NewsroomMenuFactory
|
||||
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
|
||||
*
|
||||
@@ -100,4 +110,4 @@ class NewsroomMenuFactory
|
||||
);
|
||||
return $aParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
|
||||
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem;
|
||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
|
||||
use Dict;
|
||||
use JSPopupMenuItem;
|
||||
@@ -56,30 +57,68 @@ class PopoverMenuFactory
|
||||
->SetHorizontalPosition(PopoverMenu::ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_RIGHT)
|
||||
->SetVerticalPosition(PopoverMenu::ENUM_VERTICAL_POSITION_ABOVE);
|
||||
|
||||
$aUserMenuItems = [];
|
||||
|
||||
// Allowed portals
|
||||
$aAllowedPortalsItems = static::PrepareAllowedPortalsItemsForUserMenu();
|
||||
if (!empty($aAllowedPortalsItems)) {
|
||||
$oMenu->AddSection('allowed_portals')
|
||||
->SetItems('allowed_portals', $aAllowedPortalsItems);
|
||||
}
|
||||
self::AddPopoverMenuItems($aAllowedPortalsItems, $aUserMenuItems);
|
||||
|
||||
// User related pages
|
||||
$oMenu->AddSection('user_related')
|
||||
->SetItems('user_related', static::PrepareUserRelatedItemsForUserMenu());
|
||||
self::AddPopoverMenuItems(static::PrepareUserRelatedItemsForUserMenu(), $aUserMenuItems);
|
||||
|
||||
// API: iPopupMenuExtension::MENU_USER_ACTIONS
|
||||
$aAPIItems = static::PrepareAPIItemsForUserMenu($oMenu);
|
||||
if (count($aAPIItems) > 0) {
|
||||
$oMenu->AddSection('popup_menu_extension-menu_user_actions')
|
||||
->SetItems('popup_menu_extension-menu_user_actions', $aAPIItems);
|
||||
}
|
||||
self::AddPopoverMenuItems($aAPIItems, $aUserMenuItems);
|
||||
|
||||
// Misc links
|
||||
$oMenu->AddSection('misc')
|
||||
->SetItems('misc', static::PrepareMiscItemsForUserMenu());
|
||||
/*$oMenu->AddSection('misc')
|
||||
->SetItems('misc', static::PrepareMiscItemsForUserMenu());*/
|
||||
self::AddPopoverMenuItems(static::PrepareMiscItemsForUserMenu(), $aUserMenuItems);
|
||||
|
||||
self::SortPopoverMenuItems($aUserMenuItems);
|
||||
|
||||
$oMenu->AddSection('misc')
|
||||
->AddItems('misc', $aUserMenuItems);
|
||||
return $oMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PopoverMenuItem[] $aPopoverMenuItem
|
||||
* @param PopoverMenuItem[] $aUserMenuItems
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function AddPopoverMenuItems(array $aPopoverMenuItem, array &$aUserMenuItems) : void {
|
||||
foreach ($aPopoverMenuItem as $oPopoverMenuItem){
|
||||
$aUserMenuItems[$oPopoverMenuItem->GetUID()] = $oPopoverMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PopoverMenuItem[] $aPopoverMenuItem
|
||||
* @param PopoverMenuItem[] $aUserMenuItems
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function SortPopoverMenuItems(array &$aUserMenuItems) : void {
|
||||
$aSortedMenusFromConfig = MetaModel::GetConfig()->Get('navigation_menu.sorted_popup_user_menu_items');
|
||||
if (!is_array($aSortedMenusFromConfig) || empty($aSortedMenusFromConfig)){
|
||||
return;
|
||||
}
|
||||
|
||||
$aSortedMenus = [];
|
||||
foreach ($aSortedMenusFromConfig as $sMenuUID){
|
||||
if (array_key_exists($sMenuUID, $aUserMenuItems)){
|
||||
$aSortedMenus[]=$aUserMenuItems[$sMenuUID];
|
||||
unset($aUserMenuItems[$sMenuUID]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($aUserMenuItems as $oMenu){
|
||||
$aSortedMenus[]=$oMenu;
|
||||
}
|
||||
$aUserMenuItems = $aSortedMenus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the allowed portals items for the current user
|
||||
@@ -273,4 +312,4 @@ class PopoverMenuFactory
|
||||
|
||||
return $oMenu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ use MetaModel;
|
||||
use UIExtKeyWidget;
|
||||
use UserRights;
|
||||
use utils;
|
||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenuFactory;
|
||||
|
||||
/**
|
||||
* Class NavigationMenu
|
||||
@@ -274,7 +275,7 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
|
||||
*/
|
||||
public function IsNewsroomEnabled(): bool
|
||||
{
|
||||
return MetaModel::GetConfig()->Get('newsroom_enabled');
|
||||
return (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ class NavigationMenuFactory
|
||||
{
|
||||
|
||||
$oNewsroomMenu = null;
|
||||
if (MetaModel::GetConfig()->Get('newsroom_enabled'))
|
||||
if (MetaModel::GetConfig()->Get('newsroom_enabled') && NewsroomMenuFactory::HasProviders())
|
||||
{
|
||||
$oNewsroomMenu = NewsroomMenuFactory::MakeNewsroomMenuForNavigationMenu();
|
||||
}
|
||||
@@ -57,4 +57,4 @@ class NavigationMenuFactory
|
||||
new ApplicationContext(), PopoverMenuFactory::MakeUserMenuForNavigationMenu(), $oNewsroomMenu, NavigationMenu::BLOCK_CODE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user