我想在管理界面中更新字段时修改字段设置。有没有办法在不创建ContentDefinitionEditorEventsBase类的情况下执行此操作?
以下是该字段的更新方法,我也希望能够更新字段设置(字段设置称为版本,如下所示)。保存包含此字段的内容项后,将调用此方法。
protected override DriverResult Editor(ContentPart part, DefaultTextField field, IUpdateModel updater, dynamic shapeHelper)
{
DefaultTextFieldSettings settings = field.PartFieldDefinition.Settings.GetModel<DefaultTextFieldSettings>();
var viewModel = new DefaultTextFieldDriverViewModel
{
Field = field,
Text = field.Value,
Settings = settings
};
if (updater.TryUpdateModel(viewModel, GetPrefix(field, part), null, null))
{
if (viewModel.Settings.Required && string.IsNullOrWhiteSpace(viewModel.Text))
{
updater.AddModelError("Text", T("The field {0} is mandatory", T(field.DisplayName)));
return ContentShape("Fields_Common_DefaultText_Edit", GetDifferentiator(field, part),
() => shapeHelper.EditorTemplate(TemplateName: "Fields.Common.DefaultText.Edit", Model: viewModel, Prefix: GetPrefix(field, part)));
}
if (string.Compare(field.Value, viewModel.Text, StringComparison.CurrentCulture) != 0)
{
settings.Version++;
}
field.Value = viewModel.Text;
}
return Editor(part, field, shapeHelper);
}
提前致谢。