コード例 #1
0
        /// <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);
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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);
                }
            }
        }
コード例 #4
0
ファイル: LayoutPartHandler.cs プロジェクト: anycall/Orchard
        /// <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);
                }
            }
        }
コード例 #5
0
ファイル: LayoutPartHandler.cs プロジェクト: anycall/Orchard
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        /// <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);
                }
            }
        }
コード例 #10
0
        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;
                }
            }
        }
コード例 #11
0
ファイル: LayoutEditorFactory.cs プロジェクト: Higea/Orchard
 public LayoutEditor Create(LayoutPart layoutPart) {
     return Create(layoutPart.LayoutData, layoutPart.SessionKey, layoutPart.TemplateId, layoutPart);
 }
コード例 #12
0
 private void UpdateTemplateClients(PublishContentContext context, LayoutPart part)
 {
     UpdateTemplateClients(part);
 }
コード例 #13
0
 public LayoutEditor Create(LayoutPart layoutPart)
 {
     return(Create(layoutPart.LayoutData, layoutPart.SessionKey, layoutPart.TemplateId, layoutPart));
 }
コード例 #14
0
ファイル: LayoutManager.cs プロジェクト: Higea/Orchard
        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;
        }
コード例 #15
0
 public IEnumerable <Element> ApplyTemplate(LayoutPart layout, LayoutPart templateLayout)
 {
     return(ApplyTemplate(LoadElements(layout), LoadElements(templateLayout)));
 }
コード例 #16
0
ファイル: LayoutManager.cs プロジェクト: Higea/Orchard
 public IEnumerable<Element> ApplyTemplate(LayoutPart layout, LayoutPart templateLayout) {
     return ApplyTemplate(LoadElements(layout), LoadElements(templateLayout));
 }
コード例 #17
0
ファイル: LayoutPartHandler.cs プロジェクト: anycall/Orchard
 private void UpdateTemplateClients(PublishContentContext context, LayoutPart part) {
     UpdateTemplateClients(part);
 }
コード例 #18
0
ファイル: LayoutPartHandler.cs プロジェクト: Higea/Orchard
 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);
 }