private IDList GetChildIDsSection(SectionInfo section, CallContext context) { var cls = Classes.First(x => x.Value.TemplateId == section.TemplateId.Guid).Value; var fields = cls.Properties.Where(x=>x.Attribute is SitecoreFieldAttribute); IDList fieldIds = new IDList(); var providers = Database.GetDataProviders(); var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider)); foreach (var field in fields) { if (field.Property.DeclaringType != cls.Type) continue; var attr = field.Attribute as SitecoreFieldAttribute; if (attr != null && attr.CodeFirst && attr.SectionName == section.Name) { Guid guidId = Guid.Empty; if (Utility.GuidTryParse(attr.FieldId, out guidId)) { var record = FieldTable.FirstOrDefault(x => x.FieldId.Guid == guidId); //test if the fields exists in the database: if so, we're using codefirst now, so remove it. var existing = otherProvider.GetItemDefinition(new ID(guidId), context); if (existing != null) { ID nullId = null; //hmm, there is a bug in sitecore ID's equality operator //ONLY delete fields belonging directly to this template!!! if the parent is not in the database OR if it is a codefirst class/section, we can safely delete it to prevent duplicates var existingParent = otherProvider.GetParentID(existing, context); if (existingParent == nullId || existingParent == ID.Null || this.SectionTable.Any(s => s.SectionId == existing.ID) || this.Classes.Any(c => c.Value.TemplateId == existing.ID.ToGuid())) { using (new SecurityDisabler()) otherProvider.DeleteItem(existing, context); } } if (record == null) { string fieldName = attr.FieldName.IsNullOrEmpty() ? field.Property.Name : attr.FieldName; record = new FieldInfo(new ID(guidId), section.SectionId, fieldName, attr.FieldType, attr.FieldSource, attr.FieldTitle, attr.IsShared, attr.IsUnversioned, attr.FieldSortOrder, attr.ValidationRegularExpression, attr.ValidationErrorText, attr.IsRequired); var fieldfieldInfoAttributes = field.Property.GetCustomAttributes(typeof (SitecoreFieldFieldValueAttribute), true); if (fieldfieldInfoAttributes != null && fieldfieldInfoAttributes.Any()) { foreach (var ffv in fieldfieldInfoAttributes.Cast<SitecoreFieldFieldValueAttribute>()) { record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue); } } } fieldIds.Add(record.FieldId); FieldTable.Add(record); } } } return fieldIds; }
private void GetFieldFields(FieldInfo info, FieldList fields){ if (!string.IsNullOrEmpty(info.Title)) fields.Add(TitleFieldId, info.Title); fields.Add(TypeFieldId, FieldInfo.GetFieldType(info.Type)); if (!string.IsNullOrEmpty(info.Source)) fields.Add(SourceFieldId, info.Source); fields.Add(TemplateFieldIDs.Shared, info.IsShared ? "1" : "0"); fields.Add(TemplateFieldIDs.Unversioned, info.IsUnversioned ? "1" : "0"); foreach (var fieldFieldValue in info.FieldFieldValues) { fields.Add(ID.Parse(fieldFieldValue.Key), fieldFieldValue.Value); } fields.Add(TemplateFieldIDs.Validation, info.ValidationRegularExpression ?? ""); fields.Add(TemplateFieldIDs.ValidationText, info.ValidationErrorText ?? ""); if (info.IsRequired) { fields.Add(QuickActionBarFieldId, IsRequiredId); fields.Add(ValidateButtonFieldId, IsRequiredId); fields.Add(ValidatorBarFieldId, IsRequiredId); fields.Add(WorkflowFieldId, IsRequiredId); } }