public static bool TemplateIsOrBasedOn(this Item item, BaseTemplateManager templateManager, IEnumerable<ID> templateIds) { if (item == null || templateIds == null || !templateIds.Any()) return false; var template = templateManager.GetTemplate(item.TemplateID, item.Database); if (template == null) return false; var match = from templateId in templateIds where template.DescendsFromOrEquals(templateId) select templateId; return match.Any(); }
private IEnumerable <BaseValidator> GetAdditionalValidators(Item item, Item globalFieldRulesFolder, ValidatorsMode mode) { var baseTemplates = new HashSet <string>(_templateManager.GetTemplate(item).GetBaseTemplates().Select(x => x.ID.ToString())); foreach (var globalFieldRule in GetGlobalFieldRules(globalFieldRulesFolder)) { var template = globalFieldRule[Templates.GlobalFieldRule.Fields.Template]; if (!FieldRuleAppliesToItem(item, globalFieldRule, template, baseTemplates)) { continue; } MultilistField validators = null; switch (mode) { case ValidatorsMode.Gutter: validators = globalFieldRule.Fields[Templates.FieldTypeValidationRules.Fields.QuickValidationBar]; break; case ValidatorsMode.ValidateButton: validators = globalFieldRule.Fields[Templates.FieldTypeValidationRules.Fields.ValidateButton]; break; case ValidatorsMode.ValidatorBar: validators = globalFieldRule.Fields[Templates.FieldTypeValidationRules.Fields.ValidatorBar]; break; case ValidatorsMode.Workflow: validators = globalFieldRule.Fields[Templates.FieldTypeValidationRules.Fields.Workflow]; break; } foreach (var validator in validators?.GetItems() ?? Enumerable.Empty <Item>()) { var baseValidator = BuildValidator(validator, item); baseValidator.FieldID = item.Fields[globalFieldRule[Templates.GlobalFieldRule.Fields.Field]].ID; yield return(baseValidator); } } }