Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Created November 12, 2023 21:36
Show Gist options
  • Save fluxdigital/7658b2bdc46ffb4eff70abc359cb9d84 to your computer and use it in GitHub Desktop.
Save fluxdigital/7658b2bdc46ffb4eff70abc359cb9d84 to your computer and use it in GitHub Desktop.
Adds IAR Check and message to Content Editor
### Adds IAR Check and message to Content Editor ###
#IARs method for GetItemLocations() are only available in 10.2 an above - so return if Sitecore 9 -> 10.1
$sitecoreversion = [Sitecore.Configuration.About]::Version
if ($sitecoreversion.StartsWith('9') -or $sitecoreversion.StartsWith('10.0') -or $sitecoreversion.StartsWith('10.1'))
{
#Sorry this is only for Sitecore 10.2+ and XMCloud
exit
}
#set message up as info message type first
$title = "Item as resource (IAR) info"
$iconUrl = [Sitecore.Resources.Images]::GetThemedImageSource("/~/icon/applications/16x16/document_check.png")
$text = "<img src='$($iconUrl)' alt='iar' style='vertical-align: bottom; margin-top: 5px; margin-right: 5px;'/>This item is from an item as resource file."
$icon = "Office/32x32/information.png"
#check if item is overwritten
$item = Get-Item -Path .
$aItemLocation = $item.Database.DataManager.DataSource.GetItemLocations($item.ID)
$isResource = [Sitecore.Data.DataProviders.ItemLocations.AggregatedItemLocationsExtensions]::IsResource($aItemLocation)
$isOverridden = [Sitecore.Data.DataProviders.ItemLocations.AggregatedItemLocationsExtensions]::IsOverridden($aItemLocation)
#if overritten then change the icon and message type to an warning instead
if ( $isOverridden )
{
$title = "Item as resource (IAR) warning"
$iconUrl = [Sitecore.Resources.Images]::GetThemedImageSource("/~/icon/business/16x16/data_warning.png")
$text = "<img src='$($iconUrl)' alt='iar' style='vertical-align: bottom; margin-top: 5px; margin-right: 5px;float: none;'/>This item is from an item as resource file and has been over-written."
$icon = "Office/32x32/warning.png"
}
#show the message only for IAR items
if ($isResource) {
$warning = $pipelineArgs.Add()
$warning.Title = $title
$warning.Text = $text
$warning.Icon = $icon
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment