/// <summary> /// Recursively updates all layouts that use the specified layout as its template. /// </summary> private void UpdateTemplateClients(LayoutPart part) { if (!part.IsTemplate) { return; } // When a template has changed, we need to update all layouts that use this template. // If the layout is a draft, we will update that one. // If the layout is published, we will require a new draft, perform the update, and then publish. var templateClients = _layoutManager.GetTemplateClients(part.Id, VersionOptions.Latest); foreach (var layout in templateClients) { var isPublished = layout.ContentItem.VersionRecord.Published; var draft = isPublished ? _contentManager.Get <LayoutPart>(layout.Id, VersionOptions.DraftRequired) : layout; var updatedLayout = _layoutManager.ApplyTemplate(layout, part); draft.LayoutData = _serializer.Serialize(updatedLayout); if (isPublished) { // We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again. _contentManager.Publish(draft.ContentItem); } else if (layout.IsTemplate) { UpdateTemplateClients(draft); } } }
public IEnumerable <Element> ApplyTemplate(LayoutPart layout) { var templateLayoutPart = layout.TemplateId != null?GetLayout(layout.TemplateId.Value) : default(LayoutPart); // Update the layout with the selected template, if any. return(templateLayoutPart != null?ApplyTemplate(layout, templateLayoutPart) : null); }
/// <summary> /// Recursively updates all layouts that use the specified layout as its template. /// </summary> private void UpdateTemplateClients(LayoutPart part) { if (!part.IsTemplate) return; // When a template has changed, we need to update all layouts that use this template. // If the layout is a draft, we will update that one. // If the layout is published, we will require a new draft, perform the update, and then publish. var templateClients = _layoutManager.GetTemplateClients(part.Id, VersionOptions.Latest); foreach (var layout in templateClients) { var isPublished = layout.ContentItem.VersionRecord.Published; var draft = isPublished ? _contentManager.Get<LayoutPart>(layout.Id, VersionOptions.DraftRequired) : layout; var updatedLayout = _layoutManager.ApplyTemplate(layout, part); draft.LayoutData = _serializer.Serialize(updatedLayout); if (isPublished) { // If the content being published is currently the homepage, we need to change the DisplayAlias from "" to "/" // so that the autoroute part handler will not regenerate the alias and causes the homepage to become "lost". if (IsHomePage(layout)) { PromoteToHomePage(draft); } // We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again. _contentManager.Publish(draft.ContentItem); } else if (layout.IsTemplate) { UpdateTemplateClients(draft); } } }
/// <summary> /// Recursively updates all layouts that use the specified layout as its template. /// </summary> private void UpdateTemplateClients(LayoutPart part) { if (!part.IsTemplate) return; // When a template has changed, we need to update all layouts that use this template. // If the layout is a draft, we will update that one. // If the layout is published, we will require a new draft, perform the update, and then publish. var templateClients = _layoutManager.GetTemplateClients(part.Id, VersionOptions.Latest); foreach (var layout in templateClients) { var isPublished = layout.ContentItem.VersionRecord.Published; var draft = isPublished ? _contentManager.Get<LayoutPart>(layout.Id, VersionOptions.DraftRequired) : layout; var updatedLayout = _layoutManager.ApplyTemplate(layout, part); draft.LayoutData = _serializer.Serialize(updatedLayout); if (isPublished) { // We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again. _contentManager.Publish(draft.ContentItem); } else if (layout.IsTemplate) { UpdateTemplateClients(draft); } } }
private void IndexLayout(IndexContentContext context, LayoutPart part) { var layoutShape = _contentPartDisplay.BuildDisplay(part); var layoutHtml = _shapeDisplay.Display(layoutShape); context.DocumentIndex .Add("body", layoutHtml).RemoveTags().Analyze() .Add("format", "html").Store(); }
public Form FindForm(LayoutPart layoutPart, string formName = null) { var elements = _serializer.Deserialize(layoutPart.LayoutData, new DescribeElementsContext { Content = layoutPart }); var forms = elements.Flatten().Where(x => x is Form).Cast <Form>(); return(String.IsNullOrWhiteSpace(formName) ? forms.FirstOrDefault() : forms.FirstOrDefault(x => x.Name == formName)); }
private void RemoveElements(RemoveContentContext context, LayoutPart part) { var elements = _layoutManager.LoadElements(part).ToList(); var savingContext = new LayoutSavingContext { Content = part, Elements = new List <Element>(), RemovedElements = elements }; _elementManager.Removing(savingContext); }
/// <summary> /// Recursively updates all layouts that use the specified layout as its template. /// </summary> private void UpdateTemplateClients(LayoutPart part) { if (!part.IsTemplate) { return; } // When a template has changed, we need to update all layouts that use this template. // If the layout is a draft, we will update that one. // If the layout is published, we will require a new draft, perform the update, and then publish. var templateClients = _layoutManager.GetTemplateClients(part.Id, VersionOptions.Latest); foreach (var layout in templateClients) { var isPublished = layout.ContentItem.VersionRecord.Published; var draft = isPublished ? _contentManager.Get <LayoutPart>(layout.Id, VersionOptions.DraftRequired) : layout; var updatedLayout = _layoutManager.ApplyTemplate(layout, part); draft.LayoutData = _serializer.Serialize(updatedLayout); if (isPublished) { // If the content being published is currently the homepage, we need to change the DisplayAlias from "" to "/" // so that the autoroute part handler will not regenerate the alias and causes the homepage to become "lost". if (IsHomePage(layout)) { PromoteToHomePage(draft); } // We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again. _contentManager.Publish(draft.ContentItem); } else if (layout.IsTemplate) { UpdateTemplateClients(draft); } } }
public void UpdateElement(LayoutPart layoutPart, Compound element) { if(element.ContentItemVersionId == element.ActualContentItemVersionId) return; var flattenModifiedElements = element.Elements.Flatten(); element.Elements = _layoutSerializer.Deserialize( element.Descriptor.StateBag["LayoutData"] != null ? element.Descriptor.StateBag["LayoutData"].ToString() : null, new DescribeElementsContext { Content = layoutPart }) .ToList(); var flattenOriginalElements = element.Elements.Flatten(); foreach (var originalElement in flattenOriginalElements) { var container = originalElement as Container; originalElement.IsTemplated = container != null && !container.Elements.Any(); } foreach (var originalElement in flattenOriginalElements) { var originalElementIdentifier = originalElement.GetIdentifier(); if (originalElementIdentifier == null) continue; var modifiedElement = flattenModifiedElements.FirstOrDefault(e => e.GetIdentifier() == originalElementIdentifier); if (modifiedElement == null) continue; originalElement.Data = modifiedElement.Data; var originalElementContainer = originalElement as Container; if (originalElementContainer != null && !originalElementContainer.Elements.Any()) { originalElementContainer.Elements = (modifiedElement as Container).Elements; } } }
public LayoutEditor Create(LayoutPart layoutPart) { return Create(layoutPart.LayoutData, layoutPart.SessionKey, layoutPart.TemplateId, layoutPart); }
private void UpdateTemplateClients(PublishContentContext context, LayoutPart part) { UpdateTemplateClients(part); }
public LayoutEditor Create(LayoutPart layoutPart) { return(Create(layoutPart.LayoutData, layoutPart.SessionKey, layoutPart.TemplateId, layoutPart)); }
public IEnumerable<Element> ApplyTemplate(LayoutPart layout) { var templateLayoutPart = layout.TemplateId != null ? GetLayout(layout.TemplateId.Value) : default(LayoutPart); // Update the layout with the selected template, if any. return templateLayoutPart != null ? ApplyTemplate(layout, templateLayoutPart) : null; }
public IEnumerable <Element> ApplyTemplate(LayoutPart layout, LayoutPart templateLayout) { return(ApplyTemplate(LoadElements(layout), LoadElements(templateLayout))); }
public IEnumerable<Element> ApplyTemplate(LayoutPart layout, LayoutPart templateLayout) { return ApplyTemplate(LoadElements(layout), LoadElements(templateLayout)); }
private void RemoveElements(RemoveContentContext context, LayoutPart part) { var elements = _layoutManager.LoadElements(part).ToList(); var savingContext = new LayoutSavingContext { Content = part, Elements = new List<Element>(), RemovedElements = elements }; _elementManager.Removing(savingContext); }