在 EventsPublishedContent 期间更新 ReadOnly 属性
Update ReadOnly Property during EventsPublishedContent
首先,我想在我的页面类型中添加一个只读类型 属性,这可能吗?
我想要的是一个可以编程更新的字符串 属性,但不能通过 UI,我希望内容编辑器能够看到该值但不能更改它。
假设这是可能的,我如何在发布事件期间更新此 属性 值。
那么我该如何...
private void EventsPublishedContent(object sender, ContentEventArgs e)
{
if (e.Content is MyPageType)
{
var myvalue = BusinessLogic.PerformAction(e.content)
// Now I want to save myvalue on to a property in
// e.content.myProperty
}
}
请不要在 Whosebug 上就同一主题提出多个问题
只读
只读属性是使用 [ReadOnly(true)]
或 [Editable(false)]
注释创建的。
活动
您要查找的是PublishingContent event。有很多方法可以配置这个
大多数基本上需要在初始化模块中告诉 Episerver 您想要一个事件连接到特定 IContent 类型上的特定操作。
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ContentEventHandler : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var eventRegistry = ServiceLocator.Current.GetInstance<IContentEvents>();
eventRegistry.PublishingContent += OnPublishingContent;
}
private void OnPublishingContent(object sender, ContentEventArgs e)
{
if (e.Content.Name.Contains("BlockType"))
{
e.Content.Name = e.Content.Name.Replace("BlockType", "NewName");
}
}
}
现在这当然很原始,通常我会实现 Alf Nilsson's EPiEventHelper。这样您将获得实现事件处理的通用方法
来自 https://talk.alfnilsson.se/2017/01/11/episerver-event-helper-v3-0/ 的片段。这也是您可以了解有关事件助手的更多信息的地方
[ServiceConfiguration(typeof(IPublishingContent))]
public class PublishingStandardPage : PublishingContentBase<StandardPage>
{
protected override void PublishingContent(object sender, TypedContentEventArgs e)
{
// Here you can access the standard page
StandardPage standardPage = e.Content;
}
}
首先,我想在我的页面类型中添加一个只读类型 属性,这可能吗? 我想要的是一个可以编程更新的字符串 属性,但不能通过 UI,我希望内容编辑器能够看到该值但不能更改它。
假设这是可能的,我如何在发布事件期间更新此 属性 值。
那么我该如何...
private void EventsPublishedContent(object sender, ContentEventArgs e)
{
if (e.Content is MyPageType)
{
var myvalue = BusinessLogic.PerformAction(e.content)
// Now I want to save myvalue on to a property in
// e.content.myProperty
}
}
请不要在 Whosebug 上就同一主题提出多个问题
只读
只读属性是使用 [ReadOnly(true)]
或 [Editable(false)]
注释创建的。
活动
您要查找的是PublishingContent event。有很多方法可以配置这个
大多数基本上需要在初始化模块中告诉 Episerver 您想要一个事件连接到特定 IContent 类型上的特定操作。
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ContentEventHandler : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var eventRegistry = ServiceLocator.Current.GetInstance<IContentEvents>();
eventRegistry.PublishingContent += OnPublishingContent;
}
private void OnPublishingContent(object sender, ContentEventArgs e)
{
if (e.Content.Name.Contains("BlockType"))
{
e.Content.Name = e.Content.Name.Replace("BlockType", "NewName");
}
}
}
现在这当然很原始,通常我会实现 Alf Nilsson's EPiEventHelper。这样您将获得实现事件处理的通用方法
来自 https://talk.alfnilsson.se/2017/01/11/episerver-event-helper-v3-0/ 的片段。这也是您可以了解有关事件助手的更多信息的地方
[ServiceConfiguration(typeof(IPublishingContent))]
public class PublishingStandardPage : PublishingContentBase<StandardPage>
{
protected override void PublishingContent(object sender, TypedContentEventArgs e)
{
// Here you can access the standard page
StandardPage standardPage = e.Content;
}
}