protected SPContentType GetListContentType(SPList list, ContentTypeLinkDefinition definition) { SPContentType result = null; if (!string.IsNullOrEmpty(definition.ContentTypeName)) { result = list.ContentTypes[definition.ContentTypeName]; } if (result == null && !string.IsNullOrEmpty(definition.ContentTypeId)) { var linkContentType = new SPContentTypeId(definition.ContentTypeId); // "Item" ContentTypeLink #1016 // replacing best match, it does not work on list scoped content types // Content type operations within a list // http://docs.subpointsolutions.com/spmeta2/kb/kb-m2-000003.html //var bestMatch = list.ContentTypes.BestMatch(linkContenType); //if (bestMatch.IsChildOf(linkContenType)) // result = list.ContentTypes[bestMatch]; result = list.ContentTypes .OfType <SPContentType>() .FirstOrDefault(ct => ct.Parent.Id == linkContentType); } return(result); }
public void CanDeploy_WebpartTo_VideoContentType_VideoPlayerPage() { // aiming to deploy a web part to the following page with in a library // forms/videocontenttype/videoplayerpage.aspx var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.ContentTypesEnabled = true; def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; }); var contentTypeName = "Video"; var contentTypeLinkDef = new ContentTypeLinkDefinition { ContentTypeName = contentTypeName, ContentTypeId = BuiltInSiteContentTypeId.Video }; var formsFolder = new FolderDefinition { Name = "Forms" }; var contentTypeFolder = new FolderDefinition { Name = contentTypeName }; var pageDefinition = new WebPartPageDefinition { FileName = "videoplayerpage.aspx", PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1, NeedOverride = false }; var model = SPMeta2Model.NewWebModel(web => { web.AddList(listDef, list => { list.AddContentTypeLink(contentTypeLinkDef); list.AddFolder(formsFolder, forms => { forms.AddFolder(contentTypeFolder, folder => { folder.AddHostWebPartPage(pageDefinition, page => { page.AddRandomWebpart(); page.AddRandomWebpart(); page.AddRandomWebpart(); }); }); }); }); }); TestModel(model); }
protected ContentType FindListContentType(List list, ContentTypeLinkDefinition contentTypeLinkModel) { ContentType result = null; // TODO // https://github.com/SubPointSolutions/spmeta2/issues/68 // if content type name was not provided, this fails // should be re-done by ID and Name // OOTB content types could be binded by ID, and custom content types might be binded by name // trying to find by name if (!string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeName)) { TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "ContentTypeName is not NULL. Trying to find list content type by ContentTypeName: [{0}]", contentTypeLinkModel.ContentTypeName); result = list.ContentTypes.FindByName(contentTypeLinkModel.ContentTypeName); } // trying to find by content type id // will never be resolved, actually // list content types have different ID //if (result == null && !string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeId)) // result = list.ContentTypes.GetById(contentTypeLinkModel.ContentTypeId); // trying to find by beat match if (result == null) { TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "Trying to find list content type by ContentTypeId: [{0}]", contentTypeLinkModel.ContentTypeId); // No SPContentTypeCollection.BestMatch() method avialable. // http://officespdev.uservoice.com/forums/224641-general/suggestions/6356289-expose-spcontenttypecollection-bestmatch-for-csom // TODO, correct best match impl foreach (var contentType in list.ContentTypes) { if (contentType.Id.ToString().ToUpper().StartsWith(contentTypeLinkModel.ContentTypeId.ToUpper())) { result = contentType; } } } return(result); }
public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var typedHost = (reverseHost as ContentTypeLinkReverseHost); var item = typedHost.HostContentType; var def = new ContentTypeLinkDefinition(); def.ContentTypeName = item.Name; return(new ContentTypeLinkModelNode { Options = { RequireSelfProcessing = true }, Value = def }); }
public void CanDeploy_ContentTypeLink_As_CTH_Item_ContentType() { if (!TestOptions.EnableContentTypeHubTests) { return; } WithDisabledPropertyUpdateValidation(() => { var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.TemplateType = BuiltInListTemplateTypeId.GenericList; def.ContentTypesEnabled = true; }); var ctLinkDef1 = new ContentTypeLinkDefinition { ContentTypeName = "cth-item-1", ContentTypeId = "0x01000FF176352927C44BB2DB4FBF2F30E88F" }; var ctLinkDef2 = new ContentTypeLinkDefinition { ContentTypeName = "cth-item-2", ContentTypeId = "0x010072398EFE7B102948B9BEE545225CA462" }; var webModel = SPMeta2Model.NewWebModel(web => { web.AddList(listDef, list => { list.AddContentTypeLink(ctLinkDef1); //list.AddContentTypeLink(ctLinkDef2); }); }); TestModel(webModel); }); }
public void CanDeploy_ContentTypeLink_As_CTH_Document_ContentType() { if (!TestOptions.EnableContentTypeHubTests) { return; } WithDisabledPropertyUpdateValidation(() => { var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; def.ContentTypesEnabled = true; }); var ctLinkDef1 = new ContentTypeLinkDefinition { ContentTypeName = "cth-doc-1", ContentTypeId = "0x01010021C1A5D40722E14591426E165F107547" }; var ctLinkDef2 = new ContentTypeLinkDefinition { ContentTypeName = "cth-doc-2", ContentTypeId = "0x010100429E2FB078A6984385E2531F073EA963" }; var webModel = SPMeta2Model.NewWebModel(web => { web.AddList(listDef, list => { list.AddContentTypeLink(ctLinkDef1); //list.AddContentTypeLink(ctLinkDef2); }); }); TestModel(webModel); }); }
protected ContentType FindSiteContentType(Web web, ContentTypeLinkDefinition contentTypeLinkModel) { ContentType targetContentType = null; if (!string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeName)) { targetContentType = web.AvailableContentTypes.FindByName(contentTypeLinkModel.ContentTypeName); } if (targetContentType == null && !string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeId)) { targetContentType = web.AvailableContentTypes.FindById(contentTypeLinkModel.ContentTypeId); } if (targetContentType == null) { throw new Exception(string.Format("Cannot find content type specified by model: id:[{0}] name:[{1}]", contentTypeLinkModel.ContentTypeId, contentTypeLinkModel.ContentTypeName)); } return(targetContentType); }
protected SPContentType GetListContentType(SPList list, ContentTypeLinkDefinition definition) { SPContentType result = null; if (!string.IsNullOrEmpty(definition.ContentTypeName)) { result = list.ContentTypes[definition.ContentTypeName]; } if (result == null && !string.IsNullOrEmpty(definition.ContentTypeId)) { var linkContenType = new SPContentTypeId(definition.ContentTypeId); var bestMatch = list.ContentTypes.BestMatch(linkContenType); if (bestMatch.IsChildOf(linkContenType)) { result = list.ContentTypes[bestMatch]; } } return(result); }
protected ContentType FindListContentType(List list, ContentTypeLinkDefinition contentTypeLinkModel) { // TODO // https://github.com/SubPointSolutions/spmeta2/issues/68 // if content type name was not provided, this fails // should be re-done by ID and Name // OOTB content types could be binded by ID, and custom content types might be binded by name if (!string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeName)) { return(list.ContentTypes.FindByName(contentTypeLinkModel.ContentTypeName)); } if (!string.IsNullOrEmpty(contentTypeLinkModel.ContentTypeId)) { return(list.ContentTypes.GetById(contentTypeLinkModel.ContentTypeId)); } throw new Exception( string.Format("Either ContentTypeName or ContentTypeId must be provides. Can't lookup current list content type by Name:[{0}] and ContentTypeId:[{1}] provided.", contentTypeLinkModel.ContentTypeName, contentTypeLinkModel.ContentTypeId)); }
public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeLinkDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeLinkDefinition definition) { return(AddContentTypeLink(model, definition, null)); }
public static TModelNode AddContentTypeLink <TModelNode>(this TModelNode model, ContentTypeLinkDefinition definition, Action <ContentTypeLinkModelNode> action) where TModelNode : ModelNode, IContentTypeLinkHostModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
public static TModelNode AddContentTypeLink <TModelNode>(this TModelNode model, ContentTypeLinkDefinition definition) where TModelNode : ModelNode, IContentTypeLinkHostModelNode, new() { return(AddContentTypeLink(model, definition, null)); }
public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder_At_OOTB_List_Scope() { var fieldDef = ModelGeneratorService.GetRandomDefinition <FieldDefinition>(def => { def.Hidden = false; def.ShowInDisplayForm = true; def.ShowInEditForm = true; def.ShowInListSettings = true; def.ShowInNewForm = true; def.ShowInViewForms = true; def.AddFieldOptions = BuiltInAddFieldOptions.AddToAllContentTypes | BuiltInAddFieldOptions.AddFieldInternalNameHint; }); var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.ContentTypesEnabled = false; def.TemplateType = BuiltInListTemplateTypeId.GenericList; }); var contentTypeLinkDef = new ContentTypeLinkDefinition { ContentTypeName = BuiltInContentTypeNames.Item, ContentTypeId = BuiltInContentTypeId.Item }; var webModel = SPMeta2Model.NewWebModel(web => { // adding field first web.AddList(listDef, list => { list.AddField(fieldDef, field => { }); }); // then working with the content type web.AddList(listDef.Inherit(), list => { list.AddContentTypeLink(contentTypeLinkDef, contenTypeLink => { contenTypeLink.RegExcludeFromEventsValidation(); contenTypeLink.AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition { Fields = new List <FieldLinkValue> { new FieldLinkValue { InternalName = fieldDef.InternalName }, new FieldLinkValue { InternalName = "Title" }, } }); }); }); }); TestModel(webModel); }