Created
May 6, 2020 09:25
-
-
Save davidknipe/14243810e1cb23096cee5b3c8d998059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using EPiServer.Core; | |
using EPiServer.Framework; | |
using EPiServer.Framework.Initialization; | |
using EPiServer.Shell.ObjectEditing; | |
namespace Foundation.Features | |
{ | |
public class ReadonlyBlockMetadataExtender : IMetadataExtender | |
{ | |
public void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) | |
{ | |
// Check it's a block | |
if (metadata.Model is BlockData) | |
{ | |
// Logic to decide if the user should be able to edit or not lives here | |
foreach (var modelMetadata in metadata.Properties) | |
{ | |
var property = (ExtendedMetadata)modelMetadata; | |
property.IsReadOnly = true; | |
} | |
} | |
} | |
} | |
[InitializableModule] | |
[ModuleDependency(typeof(EPiServer.Cms.Shell.InitializableModule))] | |
public class SiteMetadataExtenderInitialization : IInitializableModule | |
{ | |
public void Initialize(InitializationEngine context) | |
{ | |
if (context.HostType == HostType.WebApplication) | |
{ | |
var registry = context.Locate.Advanced.GetInstance<MetadataHandlerRegistry>(); | |
registry.RegisterMetadataHandler(typeof(ContentData), new ReadonlyBlockMetadataExtender()); | |
} | |
} | |
public void Uninitialize(InitializationEngine context) { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment