public MarkdownSiteSettingsPartHandler(IContentDefinitionManager contentDefinitionManager) { _contentDefinitionManager = contentDefinitionManager; Filters.Add(new ActivatingFilter<MarkdownSiteSettingsPart>("Site")); Filters.Add(new TemplateFilterForPart<MarkdownSiteSettingsPart>("MarkdownSiteSettings", "Parts/Markdown.MarkdownSiteSettings", "markdown")); OnInitializing<MarkdownSiteSettingsPart>((context, part) => { part.UseMarkdownForBlogs = false; }); OnUpdated<MarkdownSiteSettingsPart>((context, part) => { var blogPost = _contentDefinitionManager.GetTypeDefinition("BlogPost"); if (blogPost == null) { return; } var bodyPart = blogPost.Parts.FirstOrDefault(x => x.PartDefinition.Name == "BodyPart"); if (bodyPart == null) { return; } _contentDefinitionManager.AlterTypeDefinition("BlogPost", build => build .WithPart("BodyPart", cfg => cfg .WithSetting("BodyTypePartSettings.Flavor", part.UseMarkdownForBlogs ? "markdown" : "html") ) ); }); T = NullLocalizer.Instance; }
private IEnumerable <ContentTypeDefinition> GetContainedContentTypes(ContentTypePartDefinition typePartDefinition) { var settings = typePartDefinition.GetSettings <FlowPartSettings>(); if (settings.ContainedContentTypes == null || !settings.ContainedContentTypes.Any()) { return(_contentDefinitionManager.ListTypeDefinitions().Where(t => t.GetSettings <ContentTypeSettings>().Stereotype == "Widget")); } return(settings.ContainedContentTypes .Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)) .Where(t => t.GetSettings <ContentTypeSettings>().Stereotype == "Widget")); }
public EditTypeViewModel GetType(string name) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name); if (contentTypeDefinition == null) { return(null); } return(new EditTypeViewModel(contentTypeDefinition)); }
public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { _typeHasGDPRPart |= _contentDefinitionManager .GetTypeDefinition(builder.TypeName) .Parts .Any(ctpd => ctpd.PartDefinition.Name == "GDPRPart"); PartName = builder.Name; yield break; }
public ActionResult EditPlacement(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (contentTypeDefinition == null) { return(HttpNotFound()); } var placementModel = new EditPlacementViewModel { PlacementSettings = contentTypeDefinition.GetPlacement(PlacementType.Editor), AllPlacements = _placementService.GetEditorPlacement(id).OrderBy(x => x.PlacementSettings.Position, new FlatPositionComparer()).ThenBy(x => x.PlacementSettings.ShapeType).ToList(), ContentTypeDefinition = contentTypeDefinition, }; return(View(placementModel)); }
private GraphLookupPartSettings GetGraphLookupPartSettings(GraphLookupPart part) { ContentTypeDefinition contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); ContentTypePartDefinition?contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(GraphLookupPart)); if (contentTypePartDefinition == null) { throw new GraphSyncException($"Attempt to get {nameof(GraphLookupPartSettings)} for {part.ContentItem.ContentType}, but it doesn't have a {nameof(GraphLookupPart)}."); } return(contentTypePartDefinition.GetSettings <GraphLookupPartSettings>()); }
protected override DriverResult Editor(LayoutTemplatePart part, dynamic shapeHelper) { var isTemplate = false; var typeDefinition = _contentDefinitionManager .GetTypeDefinition(part.ContentItem.ContentType); if (typeDefinition != null) { var LayoutTemplatePart = typeDefinition .Parts .SingleOrDefault(p => p.PartDefinition.Name == "LayoutTemplatePart"); if (LayoutTemplatePart != null) { isTemplate = LayoutTemplatePart.Settings.ContainsKey("isTemplate"); } } IEnumerable <LayoutTemplatePart> layouts = null; if (isTemplate) { layouts = _layoutService .GetLayouts(); } var stylesheets = _stylesheetService.GetAvailableStylesheets().ToList(); var classes = stylesheets .ToDictionary( s => s.VirtualPath, s => s.GetClasses()); var fonts = stylesheets .ToDictionary( s => s.VirtualPath, s => s.GetFonts()); return(ContentShape("Parts_Layout_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/Layout", Model: new LayoutViewModel { Layout = part, Layouts = layouts, ParentLayoutId = part.ParentLayoutId, Stylesheets = stylesheets, Stylesheet = stylesheets.FirstOrDefault(s => s.VirtualPath == part.StylesheetPath), CssClasses = classes, Fonts = fonts, LayoutElementEditors = _layoutService.GetLayoutElementEditors(), IsTemplate = isTemplate }, Prefix: Prefix))); }
public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (contentTypeDefinition == null) { return(NotFound()); } viewModel.Settings = contentTypeDefinition.Settings; viewModel.TypeDefinition = contentTypeDefinition; viewModel.DisplayName = contentTypeDefinition.DisplayName; viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, this); if (!ModelState.IsValid) { _session.Cancel(); HackModelState(nameof(EditTypeViewModel.OrderedFieldNames)); HackModelState(nameof(EditTypeViewModel.OrderedPartNames)); return(View(viewModel)); } else { var ownedPartDefinition = _contentDefinitionManager.GetPartDefinition(contentTypeDefinition.Name); _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames); _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames); _notifier.Success(T["\"{0}\" settings have been saved.", contentTypeDefinition.Name]); } return(RedirectToAction("Edit", new { id })); }
public async Task <ContentItem> NewAsync(string contentType) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType); if (contentTypeDefinition == null) { contentTypeDefinition = new ContentTypeDefinitionBuilder().Named(contentType).Build(); } // create a new kernel for the model instance var context = new ActivatingContentContext { ContentType = contentTypeDefinition.Name, Definition = contentTypeDefinition, ContentItem = new ContentItem() { ContentType = contentTypeDefinition.Name } }; // invoke handlers to weld aspects onto kernel await Handlers.InvokeAsync((handler, context) => handler.ActivatingAsync(context), context, _logger); var context2 = new ActivatedContentContext(context.ContentItem); context2.ContentItem.ContentItemId = _idGenerator.GenerateUniqueId(context2.ContentItem); await ReversedHandlers.InvokeAsync((handler, context2) => handler.ActivatedAsync(context2), context2, _logger); var context3 = new InitializingContentContext(context2.ContentItem); await Handlers.InvokeAsync((handler, context3) => handler.InitializingAsync(context3), context3, _logger); await ReversedHandlers.InvokeAsync((handler, context3) => handler.InitializedAsync(context3), context3, _logger); // composite result is returned return(context3.ContentItem); }
public void Enabled(Feature feature) { if (feature.Descriptor.Id == "Laser.Orchard.NwazetIntegration") { //attach part to CommunicationContact if (!_contentDefinitionManager.GetTypeDefinition("CommunicationContact") .Parts.Any(pa => pa.PartDefinition.Name == "NwazetContactPart")) { _contentDefinitionManager.AlterTypeDefinition("CommunicationContact", builder => { builder.WithPart("NwazetContactPart"); }); } } }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, BodyPart part) { context.For <BodyAspect>(bodyAspect => { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(BodyPart)); var settings = contentTypePartDefinition.GetSettings <BodyPartSettings>(); var body = part.Body; bodyAspect.Body = new HtmlString(body); }); return(Task.CompletedTask); }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, MarkdownPart part) { context.For <BodyAspect>(bodyAspect => { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(MarkdownPart)); var settings = contentTypePartDefinition.GetSettings <MarkdownPartSettings>(); var html = Markdig.Markdown.ToHtml(part.Markdown ?? ""); bodyAspect.Body = new HtmlString(html); }); return(Task.CompletedTask); }
public ConnectorDescriptor DescribeConnector(string ConnectorType) { if (String.IsNullOrWhiteSpace(ConnectorType)) { throw new ArgumentException("ConnectorType is empty, can't make connector", "ConnectorType"); } var ConnectorDef = _contentDefinitionManager.GetTypeDefinition(ConnectorType); if (ConnectorDef == null) { throw new Exception(String.Format("Failed to create connector: Type definition not found: {0}", ConnectorType)); } return(new ConnectorDescriptor(ConnectorDef)); }
public override IDisplayResult Edit(AutoroutePart autoroutePart) { return(Shape <AutoroutePartViewModel>("AutoroutePart_Edit", model => { model.Path = autoroutePart.Path; model.AutoroutePart = autoroutePart; var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(autoroutePart.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, nameof(AutoroutePart), StringComparison.Ordinal)); model.Settings = contentTypePartDefinition.Settings.ToObject <AutoroutePartSettings>(); return Task.CompletedTask; })); }
public override IDisplayResult Edit(WidgetsListPart widgetPart, BuildPartEditorContext context) { return(Initialize <WidgetsListPartEditViewModel>("WidgetsListPart_Edit", m => { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(widgetPart.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(WidgetsListPart)); var settings = contentTypePartDefinition.GetSettings <WidgetsListPartSettings>(); m.AvailableZones = settings.Zones; m.WidgetsListPart = widgetPart; m.Updater = context.Updater; })); }
public void AddTerritory(TerritoryPart territory, TerritoryHierarchyPart hierarchy) { TerritoriesUtilities.ValidateArgument(territory, nameof(territory)); TerritoriesUtilities.ValidateArgument(hierarchy, nameof(hierarchy)); // check that types are correct if (territory.ContentItem.ContentType != hierarchy.TerritoryType) { var territoryTypeText = territory.ContentItem .TypeDefinition.DisplayName; var hierarchyTerritoryTypeText = _contentDefinitionManager .GetTypeDefinition(hierarchy.TerritoryType).DisplayName; throw new ArrayTypeMismatchException( T("The ContentType for the Territory ({0}) does not match the expected TerritoryType for the hierarchy ({1})", territoryTypeText, hierarchyTerritoryTypeText).Text); } // The territory may come from a different hierarchy if (territory.Record.Hierarchy != null && territory.Record.Hierarchy.Id != hierarchy.Record.Id) { // Verify that the TerritoryInternalRecords in the territory or its children can be moved there var internalRecords = new List <int>(); if (territory.Record.TerritoryInternalRecord != null) { internalRecords.Add(territory.Record.TerritoryInternalRecord.Id); } if (territory.Record.Children != null) { internalRecords.AddRange(territory .Record .Children .Where(tpr => tpr.TerritoryInternalRecord != null) .Select(tpr => tpr.TerritoryInternalRecord.Id)); } if (internalRecords.Any()) { if (hierarchy.Record .Territories .Select(tpr => tpr.TerritoryInternalRecord.Id) .Any(tir => internalRecords.Contains(tir))) { throw new TerritoryInternalDuplicateException(T("The territory being moved is already assigned in the current hierarchy.")); } } } // remove parent: This method always puts the territory at the root level of the hierarchy territory.Record.ParentTerritory = null; // set hierarchy and also set the hierarchy for all children: we need to move all levels of children, // and record.Children only contains the first level. AssignHierarchyToChildren(territory.Record, hierarchy.Record); }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, HtmlBodyPart part) { return(context.ForAsync <BodyAspect>(async bodyAspect => { if (bodyAspect != null && part.ContentItem.Id == _contentItemId) { bodyAspect.Body = _bodyAspect; return; } try { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "HtmlBodyPart")); var settings = contentTypePartDefinition.GetSettings <HtmlBodyPartSettings>(); var html = part.Html; if (!settings.SanitizeHtml) { var model = new HtmlBodyPartViewModel() { Html = part.Html, HtmlBodyPart = part, ContentItem = part.ContentItem }; html = await _liquidTemplateManager.RenderAsync(html, _htmlEncoder, model, scope => scope.SetValue("ContentItem", model.ContentItem)); } html = await _shortcodeService.ProcessAsync(html, new Context { ["ContentItem"] = part.ContentItem, ["TypePartDefinition"] = contentTypePartDefinition }); bodyAspect.Body = _bodyAspect = new HtmlString(html); _contentItemId = part.ContentItem.Id; } catch { bodyAspect.Body = HtmlString.Empty; _contentItemId = default; } })); }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, MarkdownBodyPart part) { return(context.ForAsync <BodyAspect>(async bodyAspect => { try { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, "MarkdownBodyPart")); var settings = contentTypePartDefinition.GetSettings <MarkdownBodyPartSettings>(); // The default Markdown option is to entity escape html // so filters must be run after the markdown has been processed. var html = _markdownService.ToHtml(part.Markdown); // The liquid rendering is for backwards compatability and can be removed in a future version. if (!settings.SanitizeHtml) { var model = new MarkdownBodyPartViewModel() { Markdown = part.Markdown, Html = html, MarkdownBodyPart = part, ContentItem = part.ContentItem }; html = await _liquidTemplateManager.RenderAsync(html, _htmlEncoder, model, scope => scope.SetValue("ContentItem", model.ContentItem)); } html = await _shortcodeService.ProcessAsync(html, new Context { ["ContentItem"] = part.ContentItem, ["TypePartDefinition"] = contentTypePartDefinition }); if (settings.SanitizeHtml) { html = _htmlSanitizerService.Sanitize(html); } bodyAspect.Body = new HtmlString(html); } catch { bodyAspect.Body = HtmlString.Empty; } })); }
public async Task <IActionResult> ListFirstOrDefault(string contentTypeId = "") { var query = _session.Query <ContentItem, ContentItemIndex>(); //get list items by content type id //if only 1 item exists show this item in display mode //else show default - all items if this type if (!string.IsNullOrEmpty(contentTypeId)) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentTypeId); if (contentTypeDefinition == null) { return(NotFound()); } // contentTypeDefinitions = contentTypeDefinitions.Append(contentTypeDefinition); // We display a specific type even if it's not listable so that admin pages // can reuse the Content list page for specific types. query = query.With <ContentItemIndex>(x => x.ContentType == contentTypeId); } var recordsCount = await query.CountAsync(); if (recordsCount == 1) { //redirect to display content item specific //eg /Contents/ContentItems/{contentItemId}/Display var uniqueContentItem = await _session.Query <ContentItem, ContentItemIndex>() .With <ContentItemIndex>(x => x.ContentType == contentTypeId).FirstOrDefaultAsync(); if (uniqueContentItem == null) { return(NotFound()); } return(RedirectToAction("Display", "Admin", new { area = "OrchardCore.Contents", contentItemId = uniqueContentItem.ContentItemId })); } else { //redirect to display content items //eg /Admin/Contents/ContentItems/{contentTypeId return(RedirectToAction("List", "Admin", new { area = "OrchardCore.Contents", contentTypeId = contentTypeId })); } }
public void ContentPartAttached(ContentPartAttachedContext context) { var typeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentTypeName); if (context.ContentPartName == "ProfilePart" || TypeHasProfilePart(typeDefinition)) { //see whether in the type there are any default settings to process //We only execute the providers for the part that was attached. This means we can //change the default settings of some, and they will not be reset here. foreach (var provider in _frontEndSettingsProviders .Where(prov => prov.ForParts().Contains(context.ContentPartName))) { provider.ConfigureDefaultValues(typeDefinition); } } }
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) { if (!String.IsNullOrEmpty(contentType)) { var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType); if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof(DocumentPart).Name)) { return(null); } } return(new MediaFactorySelectorResult { Priority = -10, MediaFactory = new DocumentFactory(_contentManager) }); }
protected override void Loading(LoadContentContext context) { base.Loading(context); var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.Where(f => f.FieldDefinition.Name == typeof (ContentPickerField).Name)).Cast<ContentPickerField>(); // define lazy initializer for ContentPickerField.ContentItems var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); if (contentTypeDefinition == null) { return; } foreach (var field in fields) { var localField = field; field._contentItems.Loader(() => _contentManager.GetMany<ContentItem>(localField.Ids, VersionOptions.Published, QueryHints.Empty)); } }
protected override void Loaded(LoadContentContext context) { base.Loaded(context); var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.OfType <MediaLibraryUploadField>()); if (_contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType) == null) { return; } foreach (var field in fields) { field.MediaPartsField.Loader(() => _contentManager.GetMany <MediaPart>(field.Ids, VersionOptions.Published, QueryHints.Empty).ToList()); } }
protected override void Activating(ActivatingContentContext context) { base.Activating(context); // weld the FieldIndexPart dynamically, if a field has been assigned to one of its parts var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); if (contentTypeDefinition == null) { return; } if (contentTypeDefinition.Parts.Any(p => p.PartDefinition.Fields.Any())) { context.Builder.Weld <FieldIndexPart>(); } }
protected override void Importing(ContainerPart part, ImportContentContext context) { var itemContentType = context.Attribute(part.PartDefinition.Name, "ItemContentType"); if (itemContentType != null) { if (_contentDefinitionManager.GetTypeDefinition(itemContentType) != null) { part.Record.ItemContentType = itemContentType; } } var itemsShown = context.Attribute(part.PartDefinition.Name, "ItemsShown"); if (itemsShown != null) { part.Record.ItemsShown = Convert.ToBoolean(itemsShown); } var paginated = context.Attribute(part.PartDefinition.Name, "Paginated"); if (paginated != null) { part.Record.Paginated = Convert.ToBoolean(paginated); } var pageSize = context.Attribute(part.PartDefinition.Name, "PageSize"); if (pageSize != null) { part.Record.PageSize = Convert.ToInt32(pageSize); } var orderByProperty = context.Attribute(part.PartDefinition.Name, "OrderByProperty"); if (orderByProperty != null) { part.Record.OrderByProperty = orderByProperty; } var orderByDirection = context.Attribute(part.PartDefinition.Name, "OrderByDirection"); if (orderByDirection != null) { part.Record.OrderByDirection = Convert.ToInt32(orderByDirection); } }
protected override void Activating(ActivatingContentContext context) { base.Activating(context); var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); if (contentTypeDefinition == null) { return; } // If has part SchedulingPart, weld the NotificationsPart if (contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == typeof(SchedulingPart).Name)) { context.Builder.Weld <NotificationsPart>(); } }
public async Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder builder, IEnumerable <IAdminNodeNavigationBuilder> treeNodeBuilders) { _node = menuItem as ListsAdminNode; if ((_node == null) || (!_node.Enabled)) { return; } _contentType = _contentDefinitionManager.GetTypeDefinition(_node.ContentType); if (_node.AddContentTypeAsParent) { if (_contentType == null) { _logger.LogError("Can't find The content type {0} for list admin node.", _node.ContentType); } builder.Add(new LocalizedString(_contentType.DisplayName, _contentType.DisplayName), listTypeMenu => { AddPrefixToClasses(_node.IconForParentLink).ForEach(c => listTypeMenu.AddClass(c)); listTypeMenu.Permission(ContentTypePermissions.CreateDynamicPermission( ContentTypePermissions.PermissionTemplates[Contents.Permissions.EditContent.Name], _contentType)); AddContentItems(listTypeMenu); }); } else { AddContentItems(builder); } // Add external children foreach (var childNode in _node.Items) { try { var treeBuilder = treeNodeBuilders.Where(x => x.Name == childNode.GetType().Name).FirstOrDefault(); await treeBuilder.BuildNavigationAsync(childNode, builder, treeNodeBuilders); } catch (Exception e) { _logger.LogError(e, "An exception occurred while building the '{MenuItem}' child Menu Item.", childNode.GetType().Name); } } }
private IEnumerable <ContentTypeDefinition> GetContainedContentTypes(ContentTypePartDefinition typePartDefinition) { var settings = typePartDefinition.GetSettings <BagPartSettings>(); return(settings.ContainedContentTypes.Select(contentType => { var ctd = _contentDefinitionManager.GetTypeDefinition(contentType); if (ctd != null) { return ctd.GetSettings <ContentTypeSettings>().Enabled ? ctd : null; } return null; //return _contentDefinitionManager.GetTypeDefinition(contentType); }).Where(y => y != null)); //Check for nulls }
public async Task BuildIndexAsync(BuildIndexContext context) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; } foreach (var contentTypePartDefinition in contentTypeDefinition.Parts) { var partName = contentTypePartDefinition.Name; var partTypeName = contentTypePartDefinition.PartDefinition.Name; var partActivator = _contentPartFactory.GetTypeActivator(partTypeName); var part = (ContentPart)context.ContentItem.Get(partActivator.Type, partName); var typePartIndexSettings = contentTypePartDefinition.GetSettings <ContentIndexSettings>(); // Skip this part if it's not included in the index and it's not the default type part if (partName != partTypeName && !typePartIndexSettings.Included) { continue; } await _partIndexHandlers.InvokeAsync((handler, part, contentTypePartDefinition, context, typePartIndexSettings) => handler.BuildIndexAsync(part, contentTypePartDefinition, context, typePartIndexSettings), part, contentTypePartDefinition, context, typePartIndexSettings, _logger); foreach (var contentPartFieldDefinition in contentTypePartDefinition.PartDefinition.Fields) { var partFieldIndexSettings = contentPartFieldDefinition.GetSettings <ContentIndexSettings>(); if (!partFieldIndexSettings.Included) { continue; } await _fieldIndexHandlers.InvokeAsync((handler, part, contentTypePartDefinition, contentPartFieldDefinition, context, partFieldIndexSettings) => handler.BuildIndexAsync(part, contentTypePartDefinition, contentPartFieldDefinition, context, partFieldIndexSettings), part, contentTypePartDefinition, contentPartFieldDefinition, context, partFieldIndexSettings, _logger); } } return; }
private void InitilizeLoader(ContentItem contentItem) { var fields = contentItem.Parts.SelectMany(x => x.Fields.OfType <MediaLibraryPickerField>()); // define lazy initializer for MediaLibraryPickerField.MediaParts var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); if (contentTypeDefinition == null) { return; } foreach (var field in fields) { var localField = field; localField._contentItems.Loader(() => _contentManager.GetMany <MediaPart>(localField.Ids, VersionOptions.Published, QueryHints.Empty).ToList()); } }
private async Task BuildViewModelAsync(HtmlBodyPartViewModel model, HtmlBodyPart HtmlBodyPart, ContentTypePartDefinition definition) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(HtmlBodyPart.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.Name == nameof(HtmlBodyPart)); var settings = contentTypePartDefinition.GetSettings <HtmlBodyPartSettings>(); var templateContext = new TemplateContext(); templateContext.SetValue("ContentItem", HtmlBodyPart.ContentItem); templateContext.MemberAccessStrategy.Register <HtmlBodyPartViewModel>(); model.Html = await _liquidTemplatemanager.RenderAsync(HtmlBodyPart.Html, HtmlEncoder.Default, templateContext); model.ContentItem = HtmlBodyPart.ContentItem; model.Source = HtmlBodyPart.Html; model.HtmlBodyPart = HtmlBodyPart; model.TypePartDefinition = definition; }