Copied to clipboard

Flag this post as spam?

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


  • Hubert Thalmann 57 posts 263 karma points
    Apr 25, 2019 @ 08:27
    Hubert Thalmann
    0

    Autonode in Umbraco 8

    Does anyone know if the package AutoNode is working im Umbraco 8? Or does anyone know a way to create Nodes automatically by creating another node?

    The situation is the following:

    If my Client creates a Node of the type "contentPage" i want automatically to create a Node of the type "pageComponents" as an Children of the contentPage.

    Thanks

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 26, 2019 @ 08:34
    Corné Strijkert
    0

    According to https://our.umbraco.com/packages/backoffice-extensions/autonode/ it seems it's not compatible yet.

    In Umbraco 8 you can use somehting like the following code to achieve want you want:

    public class Component : IComponent
    {
        public void Initialize()
        {
            ContentService.Published += ContentServiceOnPublished;
        }
    
        private void ContentServiceOnPublished(IContentService sender, ContentPublishedEventArgs contentPublishedEventArgs)
        {
            var publishedContent = contentPublishedEventArgs.PublishedEntities.FirstOrDefault();
            if (publishedContent != null && publishedContent.ContentType.Alias == "contentPage")
            {
                var componentsContent = sender.Create("Components Page", publishedContent.Id, "pageComponents");
    
                // if multilanguage
                componentsContent.SetCultureName("Components Page", "en-US");
    
                sender.SaveAndPublish(componentsContent);
            }
        }
    
        public void Terminate()
        {
    
        }
    }
    

    Then you can register your custom component with a composer. See: https://our.umbraco.com/documentation/Implementation/Composing/ for getting started with Umbraco composing.

  • Thomas 319 posts 606 karma points c-trib
    Jul 05, 2019 @ 08:08
    Thomas
    0

    Hey,

    Did you find a solution ? I'm sitting with a similar problem :)

Please Sign in or register to post replies

Write your reply to:

Draft