private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition) { IDList fields = new IDList(); List <string> processed = new List <string>(); var sections = template.Properties .Where(x => x.Property.DeclaringType == template.Type) .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>() .Select(x => x.SectionName); foreach (var section in sections) { if (processed.Contains(section) || section.IsNullOrEmpty()) { continue; } var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section); if (record == null) { record = new SectionInfo(section, new ID(Guid.NewGuid()), itemDefinition.ID); SectionTable.Add(record); } processed.Add(section); fields.Add(record.SectionId); } return(fields); }
/// <summary> /// Gets the fields of a specific item version. /// </summary> /// <param name="itemDefinition">The item.</param> /// <param name="versionUri">The version URI.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Data.FieldList.</returns> public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context) { if (!_setupComplete) { return(base.GetItemFields(itemDefinition, versionUri, context)); } var fields = new FieldList(); var sectionInfo = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (sectionInfo != null) { GetStandardFields(fields, sectionInfo.SectionSortOrder >= 0 ? sectionInfo.SectionSortOrder : (SectionTable.IndexOf(sectionInfo) + 100)); return(fields); } var fieldInfo = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID); if (fieldInfo != null) { GetStandardFields(fields, fieldInfo.FieldSortOrder >= 0 ? fieldInfo.FieldSortOrder : (FieldTable.IndexOf(fieldInfo) + 100)); GetFieldFields(fieldInfo, fields); return(fields); } return(base.GetItemFields(itemDefinition, versionUri, context)); }
public override global::Sitecore.Data.FieldList GetItemFields(global::Sitecore.Data.ItemDefinition itemDefinition, global::Sitecore.Data.VersionUri versionUri, CallContext context) { Setup(context); FieldList fields = new FieldList(); var sectionInfo = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (sectionInfo != null) { GetStandardFields(fields, sectionInfo.SectionSortOrder >= 0 ? sectionInfo.SectionSortOrder : (SectionTable.IndexOf(sectionInfo) + 100)); return(fields); } var fieldInfo = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID); if (fieldInfo != null) { GetStandardFields(fields, fieldInfo.FieldSortOrder >= 0 ? fieldInfo.FieldSortOrder : (FieldTable.IndexOf(fieldInfo) + 100)); GetFieldFields(fieldInfo, fields); return(fields); } return(base.GetItemFields(itemDefinition, versionUri, context)); }
/// <summary> /// Gets the child I ds template. /// </summary> /// <param name="template">The template.</param> /// <param name="itemDefinition">The item definition.</param> /// <param name="context">The context.</param> /// <param name="sqlProvider">The SQL provider.</param> /// <returns> /// IDList. /// </returns> private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context, DataProvider sqlProvider) { var fields = new IDList(); var processed = new List <string>(); var sections = template.Properties .Where(x => x.PropertyInfo.DeclaringType == template.Type) .OfType <SitecoreFieldConfiguration>() .Select(x => new { x.SectionName, x.SectionSortOrder }); //If sitecore contains a section with the same name in the database, use that one instead of creating a new one var existing = sqlProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => sqlProvider.GetItemDefinition(id, context)) .Where(item => item.TemplateID == SectionTemplateId).ToList(); foreach (var section in sections) { if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty()) { continue; } var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName); if (record == null) { var exists = existing.FirstOrDefault(def => def.Name.Equals(section.SectionName, StringComparison.InvariantCultureIgnoreCase)); var newId = GetUniqueGuid(itemDefinition.ID + section.SectionName); const int newSortOrder = 100; record = exists != null ? new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder) { Existing = true } : new SectionInfo(section.SectionName, new ID(newId), itemDefinition.ID, newSortOrder); SectionTable.Add(record); } processed.Add(section.SectionName); if (!record.Existing) { fields.Add(record.SectionId); } } //we need to add sections already in the db, 'cause we have to foreach (var sqlOne in existing.Where(ex => SectionTable.All(s => s.SectionId != ex.ID))) { SectionTable.Add(new SectionInfo(sqlOne.Name, sqlOne.ID, itemDefinition.ID, 0) { Existing = true }); } return(fields); }
private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition, CallContext context) { IDList fields = new IDList(); List <string> processed = new List <string>(); var sections = template.Properties .Where(x => x.Property.DeclaringType == template.Type) .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>() .Select(x => new { x.SectionName, x.SectionSortOrder }); var providers = Database.GetDataProviders(); var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider)); //If sitecore contains a section with the same name in the database, use that one instead of creating a new one var existing = otherProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => otherProvider.GetItemDefinition(id, context)).ToList(); foreach (var section in sections) { if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty()) { continue; } var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName); if (record == null) { var exists = existing.FirstOrDefault(def => def.Name.Equals(section)); if (exists != null) { record = new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder) { Existing = true }; } else { record = new SectionInfo(section.SectionName, new ID(Guid.NewGuid()), itemDefinition.ID, section.SectionSortOrder); } SectionTable.Add(record); } processed.Add(section.SectionName); if (!record.Existing) { fields.Add(record.SectionId); } } return(fields); }
public override global::Sitecore.Collections.IDList GetChildIDs(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context) { if (Classes.Any(x => x.Value.TemplateId == itemDefinition.ID.Guid)) { var cls = Classes.First(x => x.Value.TemplateId == itemDefinition.ID.Guid).Value; return(GetChildIDsTemplate(cls, itemDefinition)); } var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (section != null) { return(GetChildIDsSection(itemDefinition, section)); } return(base.GetChildIDs(itemDefinition, context)); }
public override global::Sitecore.Data.ID GetParentID(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context) { var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (section != null) { return(section.TemplateId); } var field = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID); if (field != null) { return(field.SectionId); } return(base.GetParentID(itemDefinition, context)); }
/// <summary> /// Gets the definition of an item. /// </summary> /// <param name="itemId">The item ID.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Data.ItemDefinition.</returns> public override global::Sitecore.Data.ItemDefinition GetItemDefinition(global::Sitecore.Data.ID itemId, CallContext context) { // Setup(context); var section = SectionTable.FirstOrDefault(x => x.SectionId == itemId); if (section != null) { return new ItemDefinition(itemId, section.Name, SectionTemplateId, ID.Null); } var field = FieldTable.FirstOrDefault(x => x.FieldId == itemId); if (field != null) { return new ItemDefinition(itemId, field.Name, FieldTemplateId, ID.Null); } return null; }
/// <summary> /// Gets the child ids of an item. /// </summary> /// <param name="itemDefinition">The item definition.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Collections.IDList.</returns> public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context) { if (!_setupComplete) { return(base.GetChildIDs(itemDefinition, context)); } if (TypeConfigurations.Any(x => x.Value.TemplateId == itemDefinition.ID)) { var cls = TypeConfigurations.First(x => x.Value.TemplateId == itemDefinition.ID).Value; return(GetChildIDsTemplate(cls, itemDefinition, context, GetSqlProvider(context.DataManager.Database))); } var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (section != null) { return(GetChildIDsSection(section, context, GetSqlProvider(context.DataManager.Database))); } return(base.GetChildIDs(itemDefinition, context)); }
/// <summary> /// Gets the child ids of an item. /// </summary> /// <param name="itemDefinition">The item definition.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Collections.IDList.</returns> public override global::Sitecore.Collections.IDList GetChildIDs(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context) { // Setup(context); if (_typeConfigurations == null) return base.GetChildIDs(itemDefinition, context); if (_typeConfigurations.Any(x => x.Value.TemplateId == itemDefinition.ID)) { var cls = _typeConfigurations.First(x => x.Value.TemplateId == itemDefinition.ID).Value; return GetChildIDsTemplate(cls, itemDefinition, context); } var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (section != null) { return GetChildIDsSection(section, context); } return base.GetChildIDs(itemDefinition, context); }
/// <summary> /// Gets the parent ID of an item. /// </summary> /// <param name="itemDefinition">The item definition.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Data.ID.</returns> public override ID GetParentID(ItemDefinition itemDefinition, CallContext context) { if (!_setupComplete) { return(base.GetParentID(itemDefinition, context)); } var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID); if (section != null) { return(section.TemplateId); } var field = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID); if (field != null) { return(field.SectionId); } return(base.GetParentID(itemDefinition, context)); }
/// <summary> /// Gets the definition of an item. /// </summary> /// <param name="itemId">The item ID.</param> /// <param name="context">The context.</param> /// <returns>Sitecore.Data.ItemDefinition.</returns> public override ItemDefinition GetItemDefinition(ID itemId, CallContext context) { if (!_setupComplete) { return(base.GetItemDefinition(itemId, context)); } var section = SectionTable.FirstOrDefault(x => x.SectionId == itemId); if (section != null) { return(new ItemDefinition(itemId, section.Name, SectionTemplateId, ID.Null)); } var field = FieldTable.FirstOrDefault(x => x.FieldId == itemId); if (field != null) { return(new ItemDefinition(itemId, field.Name, FieldTemplateId, ID.Null)); } return(base.GetItemDefinition(itemId, context)); }