当我选择一个项目时,我想先检查一些字段,然后再将其显示在“字段编辑器”中,然后更改其他字段的值。
因此,我需要订阅一个事件,但是据我所见,这种事件并不存在。有什么方法可以挂钩到项目选择操作,或者如果需要,我需要创建一个自定义事件-我需要在哪里引发它?
答案 0 :(得分:0)
您需要创建自定义验证器的声音-此博客文章描述了该过程: https://www.habaneroconsulting.com/stories/insights/2016/creating-a-custom-field-validator-in-sitecore
总结:
创建一个新的字段规则(字段验证器位于 / sitecore / system / Settings / Validation Rules / Field Rules / 中),以链接到您的程序集。上面的博客文章给出了字段验证器的以下示例
[Serializable]
namespace MySitecore.Project.Validators
{
// This validator ensures that the description attribute of a link is specified
public class LinkTextValidator : StandardValidator
{
public override string Name
{
get { return "Link text validator"; }
}
public LinkTextValidator() {}
public LinkTextValidator(SerializationInfo info, StreamingContext context) : base(info, context) { }
protected override ValidatorResult Evaluate()
{
Field field = this.GetField();
if (field == null)
return ValidatorResult.Valid;
string str1 = this.ControlValidationValue;
if (string.IsNullOrEmpty(str1) || string.Compare(str1, "<link>", StringComparison.InvariantCulture) == 0)
return ValidatorResult.Valid;
XmlValue xmlValue = new XmlValue(str1, "link");
string attribute = xmlValue.GetAttribute("text");
if (!string.IsNullOrEmpty(xmlValue.GetAttribute("text")))
return ValidatorResult.Valid;
this.Text = this.GetText("Description is missing in the link field \"{0}\".", field.DisplayName);
// return the failed result value defined in the parameters for this validator; if no Result parameter
// is defined, the default value FatalError will be used
return this.GetFailedResult(ValidatorResult.CriticalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return this.GetFailedResult(ValidatorResult.Error);
}
}
}