Skip to content

Commit

Permalink
Updated package manifest filter to set "PackageId" property in Umbrac…
Browse files Browse the repository at this point in the history
…o 12
  • Loading branch information
abjerner committed Jul 20, 2023
1 parent eafffbb commit bb38a43
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Limbo.Umbraco.YouTube/Manifests/YouTubeManifestFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Reflection;
using Umbraco.Cms.Core.Manifest;

namespace Limbo.Umbraco.YouTube.Manifests {
Expand All @@ -8,7 +9,9 @@ public class YouTubeManifestFilter : IManifestFilter {

/// <inheritdoc />
public void Filter(List<PackageManifest> manifests) {
manifests.Add(new PackageManifest {

// Initialize a new manifest filter for this package
PackageManifest manifest = new() {
AllowPackageTelemetry = true,
PackageName = YouTubePackage.Name,
Version = YouTubePackage.InformationalVersion,
Expand All @@ -20,7 +23,21 @@ public class YouTubeManifestFilter : IManifestFilter {
Stylesheets = new [] {
$"/App_Plugins/{YouTubePackage.Alias}/Styles/Default.css"
}
});
};

// The "PackageId" property isn't available prior to Umbraco 12, and since the package is build against
// Umbraco 10, we need to use reflection for setting the property value for Umbraco 12+. Ideally this
// shouldn't fail, but we might at least add a try/catch to be sure
try {
PropertyInfo? property = manifest.GetType().GetProperty("PackageId");
property?.SetValue(manifest, YouTubePackage.Alias);
} catch {
// We don't really care about the exception
}

// Append the manifest
manifests.Add(manifest);

}

}
Expand Down

0 comments on commit bb38a43

Please sign in to comment.