private TabPlacementSettings[] GetStoredTabForPlacement(ContentTypeDefinition contentTypeDefinition, PlacementType placementType)
        {
            var currentSettings = contentTypeDefinition.Settings;
            var serializer      = new JavaScriptSerializer();

            currentSettings.TryGetValue("ContentTypeSettings.Placement." + placementType, out string placement);

            return(String.IsNullOrEmpty(placement) ? new TabPlacementSettings[0] : serializer.Deserialize <TabPlacementSettings[]>(placement));
        }
 private bool TypeHasIdentity(ContentTypeDefinition definition)
 {
     return(definition
            .Parts.Any(pa =>
                       PartsWithIdentity
                       .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                       .Select(s => s.Trim())
                       .Contains(pa.PartDefinition.Name)));
 }
 /// <summary>
 /// Generates a permission dynamically for a content type
 /// </summary>
 public static Permission CreateDynamicPermission(Permission template, ContentTypeDefinition typeDefinition)
 {
     return(new Permission {
         Name = String.Format(template.Name, typeDefinition.Name),
         Description = String.Format(template.Description, typeDefinition.DisplayName),
         Category = typeDefinition.DisplayName,
         ImpliedBy = (template.ImpliedBy ?? new Permission[0]).Select(t => CreateDynamicPermission(t, typeDefinition))
     });
 }
示例#4
0
 private IEnumerable <EditTypePartViewModel> GetTypeParts(ContentTypeDefinition contentTypeDefinition)
 {
     return(contentTypeDefinition.Parts
            .Where(p => !string.Equals(p.PartDefinition.Name, Name, StringComparison.OrdinalIgnoreCase))
            .Select((p, i) => new EditTypePartViewModel(i, p)
     {
         Type = this
     }));
 }
示例#5
0
 public EditTypeViewModel(ContentTypeDefinition contentTypeDefinition)
 {
     Name        = contentTypeDefinition.Name;
     DisplayName = contentTypeDefinition.DisplayName;
     Settings    = contentTypeDefinition.Settings;
     Fields      = GetTypeFields(contentTypeDefinition).ToList();
     Parts       = GetTypeParts(contentTypeDefinition).ToList();
     _Definition = contentTypeDefinition;
 }
示例#6
0
 /// <summary>
 /// Generates a permission dynamically for a content type
 /// </summary>
 public static Permission CreateSubmitPermission(ContentTypeDefinition typeDefinition)
 {
     return(new Permission {
         Name = String.Format(SubmitForm.Name, typeDefinition.Name),
         Description = String.Format(SubmitForm.Description, typeDefinition.DisplayName),
         Category = "Custom Forms",
         ImpliedBy = new [] { SubmitForm }
     });
 }
        public override IEnumerable <TemplateViewModel> TypeEditor(ContentTypeDefinition definition)
        {
            var settings = definition.Settings.GetModel <ContentPermissionsTypeSettings>();
            var model    = new SecurableContentItemsSettingsViewModel {
                SecurableContentItems = settings.SecurableContentItems,
            };

            yield return(DefinitionTemplate(model));
        }
示例#8
0
        public void ShouldReturnTrueWhenUpdatingWithDifferentProperties(Action <ContentType> setDifferentProperty)
        {
            var originalContentType = CreateDefaultContentType();
            var contentTypeClone    = CloneContentType(originalContentType);
            var definition          = new ContentTypeDefinition(contentTypeClone, null);

            setDifferentProperty(originalContentType);
            Assert.True(definition.Update(originalContentType));
        }
示例#9
0
        public OrchardQueryable(ContentTypeDefinition type, OrchardDataSource dataSource)
        {
            _type       = type;
            _dataSource = dataSource;

            Provider    = new OrchardQueryProvider(type, _dataSource);
            Expression  = Expression.Constant(this);
            ElementType = typeof(ContentItem);
        }
示例#10
0
        public static string For(ContentTypeDefinition contentTypeDefinition)
        {
            if (contentTypeDefinition == null)
            {
                return(null);
            }

            return($"ItemLevelCache-ContentType-{contentTypeDefinition.Name}");
        }
示例#11
0
        public PlacementSettings[] GetFrontEndPlacement(ContentTypeDefinition contentTypeDefinition)
        {
            var    currentSettings = contentTypeDefinition.Settings;
            string placement;
            var    serializer = new JavaScriptSerializer();

            currentSettings.TryGetValue("ContentTypeSettings.Placement.ProfileFrontEndEditor", out placement);

            return(String.IsNullOrEmpty(placement) ? new PlacementSettings[0] : serializer.Deserialize <PlacementSettings[]>(placement));
        }
 private async Task BuildContentPartsDisplaysAsync(
     ContentItem contentItem,
     ContentTypeDefinition contentTypeDefinition,
     BuildDisplayContext context)
 {
     foreach (var contentTypePartDescriptor in contentTypeDefinition.Parts)
     {
         await BuildContentPartDisplaysAsync(contentItem, contentTypePartDescriptor, context);
     }
 }
示例#13
0
 public virtual void ConfigureDefaultValues(ContentTypeDefinition definition, params string[] options)
 {
     if (TypeHasProfilePart(definition))   //sanity check
     {
         _contentDefinitionManager.AlterTypeDefinition(definition.Name,
                                                       typeBuilder =>
                                                       typeBuilder.WithPart(PartName,
                                                                            partBuilder => ProfileFrontEndSettings.SetValues(partBuilder, AllowDisplay, AllowEdit)));
     }
 }
示例#14
0
        public void ShouldReturnFalseWhenUpdatingSameOrIncorrectEditorInterfaces(List <EditorInterfaceControl> controls)
        {
            var baseEditorInterface = new EditorInterface();
            var newEditorInterface  = CreateDefaultNewEditorInterface();
            var definition          = new ContentTypeDefinition(null, newEditorInterface);

            baseEditorInterface.Controls = controls;

            Assert.False(definition.Update(baseEditorInterface));
        }
        public static PlacementSettings[] GetPlacement(this ContentTypeDefinition contentTypeDefinition, PlacementType placementType)
        {
            var    currentSettings = contentTypeDefinition.Settings;
            string placement;
            var    serializer = new JavaScriptSerializer();

            currentSettings.TryGetValue("ContentTypeSettings.Placement." + placementType, out placement);

            return(String.IsNullOrEmpty(placement) ? new PlacementSettings[0] : serializer.Deserialize <PlacementSettings[]>(placement));
        }
        /// <summary>
        /// Constructs a new Content Item Builder instance.
        /// </summary>
        /// <param name="definition">The definition for the content item to be built.</param>
        public ContentItemBuilder(ContentTypeDefinition definition)
        {
            _definition = definition;

            // TODO: could / should be done on the build method ?
            _item = new ContentItem {
                ContentType    = definition.Name,
                TypeDefinition = definition
            };
        }
示例#17
0
 private void Create()
 {
     belongToProjectField       = GetBelognToProjectField();
     documentResponsibleField   = GetDocumentResponsibleField();
     documentTypeField          = GetDocumentTypeField();
     expirationDateField        = GetExpirationDateField();
     projectDocumentsList       = GetProjectDocumentsList();
     projectDocumentContemtType = GetProjectDocumentContemtType();
     projectDocumentsListView   = GetProjectDocumentsListView();
 }
示例#18
0
        public void ShouldReturnTrueForUpdatedFields(Action <List <Field> > modifyFields)
        {
            var originalContentType = CreateDefaultContentType();
            var contentTypeClone    = CloneContentType(originalContentType);
            var definition          = new ContentTypeDefinition(contentTypeClone, null);

            modifyFields(originalContentType.Fields);

            Assert.True(definition.Update(originalContentType));
        }
示例#19
0
        public void CSOMConsoleAppSample(string[] args)
        {
            var siteUrl = "http://tesla-dev:31415/";


            // define fields
            var clientDescriptionField = new FieldDefinition
            {
                Title        = "Client Description",
                InternalName = "dcs_ClientDescription",
                Group        = "SPMeta2.Samples",
                Id           = new Guid("06975b67-01f5-47d7-9e2e-2702dfb8c217"),
                FieldType    = BuiltInFieldTypes.Note,
            };

            var clientNumberField = new FieldDefinition
            {
                Title        = "Client Number",
                InternalName = "dcs_ClientNumber",
                Group        = "SPMeta2.Samples",
                Id           = new Guid("22264486-7561-45ec-a6bc-591ba243693b"),
                FieldType    = BuiltInFieldTypes.Number,
            };


            // define content type
            var customerAccountContentType = new ContentTypeDefinition
            {
                Name = "Customer Account",
                Id   = new Guid("ddc46a66-19a0-460b-a723-c84d7f60a342"),
                ParentContentTypeId = BuiltInContentTypeId.Item,
                Group = "SPMeta2.Samples",
            };

            // define relationships and the model
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site
                .AddField(clientDescriptionField)
                .AddField(clientNumberField)
                .AddContentType(customerAccountContentType, contentType =>
                {
                    contentType
                    .AddContentTypeFieldLink(clientDescriptionField)
                    .AddContentTypeFieldLink(clientNumberField);
                });
            });

            var clientContext = new ClientContext(siteUrl);

            // deploy the model to the SharePoint site over CSOM
            var csomProvisionService = new CSOMProvisionService();

            csomProvisionService.DeploySiteModel(clientContext, siteModel);
        }
        public void Deploy_ContentTypesToList()
        {
            // Step 1, define security groups
            var contractsList = new ListDefinition
            {
                Title               = "Customer contracts",
                Url                 = "CustomerContracts",
                Description         = "Stores customer related contracts.",
                TemplateType        = BuiltInListTemplateTypeId.DocumentLibrary,
                ContentTypesEnabled = true
            };

            var standardContract = new ContentTypeDefinition
            {
                Id   = new Guid("49fbbb62-f8cd-4372-94a0-756e55a8945e"),
                Name = "Standard Contract",
                ParentContentTypeId = BuiltInContentTypeId.Document,
                Group = SampleConsts.DefaultMetadataGroup
            };

            var legacyContract = new ContentTypeDefinition
            {
                Id   = new Guid("ba049ddb-962a-4b8e-80a0-2bd10a6c4a88"),
                Name = "Legacy Contract",
                ParentContentTypeId = BuiltInContentTypeId.Document,
                Group = SampleConsts.DefaultMetadataGroup
            };

            // Step 2, define web model and artifact relationships - add security groups t the web
            // Deploy site model first - content types to site
            var siteModel = SPMeta2Model
                            .NewSiteModel(site =>
            {
                site
                .AddContentType(standardContract)
                .AddContentType(legacyContract);
            });

            DeploySiteModel(siteModel);

            // deploy web model - list and add content type links to list
            var webModel = SPMeta2Model
                           .NewWebModel(web =>
            {
                web
                .AddList(contractsList, list =>
                {
                    list
                    .AddContentTypeLink(standardContract)
                    .AddContentTypeLink(legacyContract);
                });
            });

            DeployWebModel(webModel);
        }
示例#21
0
 public Task BuildTypeEditorAsync(ContentTypeDefinition model, BuildEditorContext context)
 {
     return(_typeDisplayDrivers.InvokeAsync(async(contentDisplay, model, context) =>
     {
         var result = await contentDisplay.BuildEditorAsync(model, context);
         if (result != null)
         {
             await result.ApplyAsync(context);
         }
     }, model, context, _logger));
 }
 /// <summary>
 /// Generates a permission dynamically for a content type
 /// </summary>
 public static Permission CreateDynamicPermission(Permission template, ContentTypeDefinition typeDefinition)
 {
     return(new Permission(
                String.Format(template.Name, typeDefinition.Name),
                String.Format(template.Description, typeDefinition.DisplayName),
                (template.ImpliedBy ?? Array.Empty <Permission>()).Select(t => CreateDynamicPermission(t, typeDefinition))
                )
     {
         Category = typeDefinition.DisplayName
     });
 }
示例#23
0
        private string GetCreateUrl(ContentTypeDefinition contentTypeDefinition, ContentItem prmContentItem, IUrlHelper urlHelper)
        {
            //<a class="dropdown-item" asp-action="Create" asp-controller="Admin" asp-route-id="@containedContentTypeDefinition.Name" asp-route-area="OrchardCore.Contents" asp-route-ListPart.ContainerId="@Model.ListPart.ContentItem.ContentItemId">@containedContentTypeDefinition.DisplayName</a>

            return(urlHelper.Action("Create", "Admin",
                                    new RouteValueDictionary {
                { "Area", "OrchardCore.Contents" },
                { "id", contentTypeDefinition.Name },
                { "ListPart.ContainerId", prmContentItem.ContentItemId },
            }));
        }
 public Task UpdateTypeEditorAsync(ContentTypeDefinition model, UpdateTypeEditorContext context)
 {
     return(_typeDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.UpdateEditorAsync(model, context);
         if (result != null)
         {
             await result.ApplyAsync(context);
         }
     }, Logger));
 }
示例#25
0
        private IEnumerable <EditPartFieldViewModel> GetTypeFields(ContentTypeDefinition contentTypeDefinition)
        {
            var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => string.Equals(p.PartDefinition.Name, Name, StringComparison.OrdinalIgnoreCase));

            return(implicitTypePart == null
                ? Enumerable.Empty <EditPartFieldViewModel>()
                : implicitTypePart.PartDefinition.Fields.Select((f, i) => new EditPartFieldViewModel(i, f)
            {
                Part = new EditPartViewModel(implicitTypePart.PartDefinition)
            }));
        }
        public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition)
        {
            return(Initialize <FullTextAspectSettingsViewModel>("FullTextAspectSettings_Edit", model =>
            {
                var settings = contentTypeDefinition.GetSettings <FullTextAspectSettings>();

                model.IncludeFullTextTemplate = settings.IncludeFullTextTemplate;
                model.FullTextTemplate = settings.FullTextTemplate;
                model.IncludeDisplayText = settings.IncludeDisplayText;
                model.IncludeBodyAspect = settings.IncludeBodyAspect;
            }).Location("Content:6"));
        }
        public EditPlacementViewModel GetEditPlacementViewModel(ContentTypeDefinition contentTypeDefinition)
        {
            var storedPlacement = GetStoredTabForPlacement(contentTypeDefinition, PlacementType.Editor);
            var placementFromPlacementEditor = GetTabFromLocation(contentTypeDefinition.Name);

            return(new EditPlacementViewModel
            {
                PlacementSettings = storedPlacement,
                AllPlacements = placementFromPlacementEditor.OrderBy(x => x.PlacementSettings.Position, new FlatPositionComparer()).ThenBy(x => x.PlacementSettings.ShapeType).ToList(),
                ContentTypeDefinition = contentTypeDefinition,
            });
        }
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanHideContentTypeFields()
        {
            var hiddenNotesField = new NoteFieldDefinition
            {
                Title        = "Hidden Notes",
                InternalName = "m2_HiddenNotes",
                Group        = "SPMeta2.Samples",
                Id           = new Guid("13C47F4C-F3BA-431E-A76B-FCC03FED4E9B"),
            };

            var publicNotesField = new NoteFieldDefinition
            {
                Title        = "Publis Notes",
                InternalName = "m2_PublicNotes",
                Group        = "SPMeta2.Samples",
                Id           = new Guid("BACEE8AA-90B4-4268-8257-EEA0706942E4"),
            };

            var hiddenNotesContentType = new ContentTypeDefinition
            {
                Name = "M2 Hidden Notes",
                Id   = new Guid("1166D859-CC4B-4A5F-A1F3-28BE508C5A92"),
                ParentContentTypeId = BuiltInContentTypeId.Item,
                Group = "SPMeta2.Samples"
            };

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site
                .AddField(hiddenNotesField)
                .AddField(publicNotesField)
                .AddContentType(hiddenNotesContentType, contentType =>
                {
                    contentType
                    .AddContentTypeFieldLink(hiddenNotesField)
                    .AddContentTypeFieldLink(publicNotesField)
                    .AddHideContentTypeFieldLinks(new HideContentTypeFieldLinksDefinition
                    {
                        Fields = new List <FieldLinkValue>
                        {
                            new FieldLinkValue {
                                Id = BuiltInFieldId.Title
                            },
                            new FieldLinkValue {
                                Id = hiddenNotesField.Id
                            }
                        }
                    });
                });
            });

            DeployModel(model);
        }
        private RelationshipDataModel TransformContentTypeDefinitionToRelationship(ContentTypeDefinition contentTypeDefinition, string linkFromName, string linkToName)
        {
            var relationshipDataModel = new RelationshipDataModel
            {
                Id     = contentTypeDefinition.Name,
                Label  = contentTypeDefinition.DisplayName,
                Domain = linkFromName,
                Range  = linkToName,
            };

            return(relationshipDataModel);
        }
示例#30
0
        public ActionResult EditContentItem(long?contentItemId = null, int?contentTypeId = null)
        {
            pageResourceManager.InsertTitlePart("编辑资讯");
            var metadataService = new MetadataService();
            ContentTypeDefinition contentType = null;
            ContentItem           item        = null;

            if (contentItemId.HasValue && contentItemId.Value > 0)
            {
                item = contentItemService.Get(contentItemId.Value);
                if (item == null)
                {
                    return(HttpNotFound());
                }
                contentType = item.ContentType;
            }
            else
            {
                if (contentTypeId.HasValue && contentTypeId.Value > 0)
                {
                    contentType = metadataService.GetContentType(contentTypeId.Value);
                }
                else
                {
                    contentType = metadataService.GetContentTypes(true).FirstOrDefault();
                }
                if (contentType == null)
                {
                    return(HttpNotFound());
                }
            }
            ContentItemEditModel model = TempData.Get <ContentItemEditModel>("ContentItemEditModel", null);

            if (model == null)
            {
                if (item != null)
                {
                    model = item.AsEditModel();
                }
                else
                {
                    model = new ContentItemEditModel {
                        ContentTypeId = contentType.ContentTypeId, ReleaseDate = DateTime.Now
                    };
                }
            }
            else
            {
                TempData.Remove("ContentItemEditModel");
            }
            ViewData["contentItem"] = item;
            return(View(contentItemId.HasValue ? contentType.Page_Edit : contentType.Page_New, model));
        }