Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sonja 133 posts 621 karma points
    Jun 27, 2019 @ 07:00
    Sonja
    0

    when create content, create it for 2 document types at once

    hi

    I have 2 document types: first one is named BasePage and second one PageComponents. Now in Permitions BasePage is Allowed as root and has Allowed Child node types PageComponents.

    How do I make it so when in Content I'm creating BasePage, I create BasePage and PageComponents under it all at one

    please advice

  • Natalie 22 posts 162 karma points
    Jun 27, 2019 @ 07:13
    Natalie
    0

    Hullo,

    I think you can create BasePage and PageComponent in content. And just PageComponent Under BasePage... Unless you don't have the right, you can create all your document type under content and only the ones you decide by setting them up as a child, under the other document types.

    I hope it help...

  • Sonja 133 posts 621 karma points
    Jun 27, 2019 @ 07:30
    Sonja
    0

    Hi, Natalie,

    that's not the point. The requirement is that whenever I create BasePage, the PageComponents should be created automatically under it.

    please advice

  • Natalie 22 posts 162 karma points
    Jun 27, 2019 @ 08:14
    Natalie
    0

    Thing like that : Image

    Meaning my "Accueil" is your BasePage and my "Page" is your PageComponent ?!? When I create My Accueil, I have the Page component avalaible to be created under it. If I create a new Accueil, I could also create page underneath.

  • Sonja 133 posts 621 karma points
    Jun 27, 2019 @ 09:49
    Sonja
    0

    Natalie, All this is already present. However when I create Accuil (my BasePage) automatically one Page (my PageComponent) should be created, that is requirement. 2 creations with 1 step

  • Sonja 133 posts 621 karma points
    Jun 28, 2019 @ 07:11
    Sonja
    0

    Guys, does anybody else have a suggestion? It is possible because I've seen it on USkinned

  • Sonja 133 posts 621 karma points
    Jul 10, 2019 @ 07:52
    Sonja
    100

    I've solved it. needs to override ContentService_Saved where we check if the content service is from the required content type to add another content service as child. This means in Umbraco 8 need to do the following:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class MyComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            //composition.SetContentLastChanceFinder<My404ContentFinder>();
    
            composition.Components().Append<MyComponent>();
        }
    }
    
    class MyComponent : IComponent
    {
        public void Initialize()
        {
            ContentService.Saved += this.ContentService_Saved;
        }
    
        public void Terminate()
        {
        }
        private void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
        {
            long totalChildren;
            var contentService = sender;
            var ents = e.SavedEntities.Where(x => x.ContentType.Alias == "myPage");
    
            foreach (var node in ents)
            {
    
                if (!contentService.GetPagedChildren(node.Id, 0, 10, out totalChildren).Any(x => x.ContentType.Alias == "ComponentFolder"))
                {
                    var pageComponentsFolder = contentService.CreateContent("Components", node.GetUdi(), "ComponentFolder");
                    contentService.SaveAndPublish(pageComponentsFolder);
    
                }
           }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft