When building a menu you would probably build it based on the page tree structure, where each menu item would be a regular link to a page.
However, sometimes you would like one of the links to point to another page, a media file or an external site. Here comes the Shortcut functionality which allows you to do just that.
Unfortunately in the current EPiServer version (10.8.0) it’s not possible to select a media file using the default Content Selector. The URL has to be set manually as an external URL.
For now, until it’s not implemented in the EPiServer itself you can use this simple workaround:
I prepared a custom EditorDescriptor that adds MediaData to the AllowedTypes collection. The target class for the EditorDescriptor (ShortcutBlock) is internal, so the editor has to be registered manually.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
using System; using System.Collections.Generic; using System.Linq; using EPiServer.Cms.Shell.UI; using EPiServer.Core; using EPiServer.Framework; using EPiServer.Framework.Initialization; using EPiServer.ServiceLocation; using EPiServer.Shell.ObjectEditing; using EPiServer.Shell.ObjectEditing.EditorDescriptors; namespace AlloyTemplates.Business.Initialization { [InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] [ModuleDependency(typeof(EPiServer.Shell.UI.InitializationModule))] public class ProviderInitializationModule : IInitializableModule { public void Initialize(InitializationEngine context) { // find the ShortcutBlock type var shortcutBlock = typeof(GroupedMetaDataPropertyInfo).Assembly.GetType("EPiServer.Cms.Shell.UI.ObjectEditing.InternalMetadata.ShortcutBlock"); var metadataHandlerRegistry = ServiceLocator.Current.GetInstance<MetadataHandlerRegistry>(); var defaultHandler = metadataHandlerRegistry.GetMetadataHandlers(shortcutBlock).OfType<EditorDescriptor>().FirstOrDefault(); metadataHandlerRegistry.RegisterMetadataHandler(shortcutBlock, new FixedShortcutBlockEditorDescriptor(defaultHandler), null, EditorDescriptorBehavior.OverrideDefault); } public void Uninitialize(InitializationEngine context) { } } public class FixedShortcutBlockEditorDescriptor : EditorDescriptor { private readonly EditorDescriptor _original; public FixedShortcutBlockEditorDescriptor(EditorDescriptor original) { _original = original; } public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) { this._original.ModifyMetadata(metadata, attributes); var pageShortcutLink = (ExtendedMetadata) metadata.Properties.Single(p => p.PropertyName == "PageShortcutLink"); pageShortcutLink.EditorConfiguration["AllowedTypes"] = new[] { typeof(PageData), typeof(MediaData) }.Select(a => a.FullName.ToLowerInvariant()); } } } |
After running the site and opening the Content Selector, the editor is now able to select a media file.