Files
Megamenu/deployment/add-megamenu.ps1
Torsten Brendgen 50b85468f1 feat: Enhance MegaMenu with localization, caching, and new properties
- Added localization support for loading states, empty navigation, and submenu actions in both German and English.
- Introduced new properties in IMenuItem for description, openInNewWindow, and external links.
- Updated SPTermStorePickerService to handle cache versioning and language-specific caching.
- Implemented a new MegaMenuCore service for handling term properties, cache management, and navigation URL resolution.
- Refactored TaxonomyNavigationService to build menu hierarchy and filter hidden terms.
- Added automated tests for MegaMenu core functionalities and static asset validation.
- Removed unused ItemDictionary service.
- Created a comprehensive ToDo document outlining the implementation status and future tasks.
2026-07-20 21:34:24 +02:00

119 lines
3.7 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$SiteUrl,
[string]$TermSetName = '',
[string]$TermSetId = '',
[ValidateRange(1, 1440)]
[int]$CacheMinutes = 15,
[string]$CacheVersion = '1',
[ValidateSet('megaMenu', 'flyout')]
[string]$MenuMode = 'megaMenu',
[switch]$EnableDebug,
[string]$Description = 'MSFT-Custom-Solution:MegaMenu'
)
if (-not (Get-Command -Name Get-SPSite -ErrorAction SilentlyContinue)) {
if (Get-Module -ListAvailable -Name Microsoft.SharePoint.PowerShell) {
Import-Module Microsoft.SharePoint.PowerShell -DisableNameChecking
}
elseif (Get-PSSnapin -Registered -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
else {
throw 'Die SharePoint PowerShell-Komponenten wurden nicht gefunden. Bitte in der SharePoint Management Shell ausfuehren.'
}
}
$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506'
$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b'
$legacyPropertyName = 'PortalSettings.MegaMenu.Configuration'
if ([string]::IsNullOrWhiteSpace($TermSetId) -and [string]::IsNullOrWhiteSpace($TermSetName)) {
throw 'Bitte TermSetId oder TermSetName angeben.'
}
$properties = [string](@{
termSetName = $TermSetName.Trim()
termSetId = $TermSetId.Trim()
cacheMinutes = $CacheMinutes
cacheVersion = $CacheVersion
menuMode = $MenuMode
debug = [bool]$EnableDebug.IsPresent
} | ConvertTo-Json -Depth 10 -Compress)
$site = Get-SPSite -Identity $SiteUrl
try {
@($site.UserCustomActions | Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}) | ForEach-Object {
Write-Host ('Entferne alte Site-Action: ' + $_.Id)
$_.Delete()
}
try {
if ($site.RootWeb.AllProperties.ContainsKey($legacyPropertyName)) {
$site.RootWeb.AllProperties.Remove($legacyPropertyName)
$site.RootWeb.Update()
Write-Host ('Alte Property-Bag-Konfiguration entfernt: ' + $legacyPropertyName)
}
}
catch {
Write-Warning ('Die alte Property-Bag-Konfiguration konnte nicht entfernt werden: ' + $_.Exception.Message)
}
foreach ($web in $site.AllWebs) {
try {
$webUrl = $web.Url
$actions = @($web.UserCustomActions | Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
})
foreach ($action in $actions) {
Write-Host ('Entferne alte Web-Action: ' + $webUrl + ' / ' + $action.Id)
$action.Delete()
}
}
finally {
$web.Dispose()
}
}
}
finally {
$site.Dispose()
}
$site = Get-SPSite -Identity $SiteUrl
try {
$action = $site.UserCustomActions.Add()
$action.Name = [Guid]::NewGuid().ToString('B')
$action.Title = 'MegaMenu Application Customizer'
$action.Description = $Description
$action.Location = 'ClientSideExtension.ApplicationCustomizer'
$action.ClientSideComponentId = $componentId
$action.ClientSideComponentProperties = $properties
$action.Sequence = 100
$action.Update()
Write-Host ''
Write-Host 'MegaMenu wurde zentral fuer die Site Collection registriert.' -ForegroundColor Green
Write-Host ('Site Collection: ' + $site.Url)
Write-Host ('Action-ID: ' + $action.Id)
Write-Host ('Menu mode: ' + $MenuMode)
Write-Host ('Properties: ' + $properties)
Write-Host 'Das MegaMenu-SPFx-Paket muss im App Catalog zentral bereitgestellt sein.' -ForegroundColor Yellow
}
finally {
$site.Dispose()
}